To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.javaOpen lugnet.robotics.rcx.java in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / Java / 182
181  |  183
Subject: 
Java version of DiscShooter
Newsgroups: 
lugnet.robotics.rcx.java
Date: 
Wed, 19 Jun 2002 02:16:23 GMT
Viewed: 
3821 times
  
Since there doesn't seem to be alot of activity in the java group
(particularly for beginners), I'm posting my java version of the DiscShooter
program from the Advanced Builders Set.  Let's see some other examples out
there!

/**
* @author robweeks
*
* To change this generated comment edit the template variable
"typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
import josx.platform.rcx.*;

public class DiscShooter implements SensorConstants {

public DiscShooter() {
  Sensor.S2.setTypeAndMode(SENSOR_TYPE_LIGHT ,SENSOR_MODE_PCT);
  Sensor.S2.activate();
  Sensor.S3.setTypeAndMode(SENSOR_TYPE_TOUCH,SENSOR_MODE_BOOL);
  Motor.A.setPower(7);
  Motor.C.setPower(7);
  Motor.B.setPower(7);
}

public static void main(String[] args) {
  DiscShooter bot = new DiscShooter();
  Motor.C.forward();
  Motor.B.backward();
  for (int numDiscs = 1; numDiscs < 7; numDiscs++) {
   while (bot.isBright() != true); // wait for the disc to get past light
sensor
   try {Thread.sleep(500);} catch (Exception e) {}
   if (numDiscs % 2 == 0 ) {
    Motor.A.backward();
   } else {
    Motor.A.forward();
   }
    for (int turnGun = 1; turnGun < 6; turnGun++) {
     while (Sensor.S3.readBooleanValue() == true);
     while (Sensor.S3.readBooleanValue() == false);
    }
   Motor.A.stop();

  }
  try {Thread.sleep(2000);} catch (Exception e) {}
  Motor.B.stop();
  Motor.C.stop();
}

public boolean isBright() {
  return (Sensor.S2.readValue() > 30);
}
}

p.s. kudos to Brian Bagnall on his excellent book "Core Lego Mindstorms
Programming".  It has really changed my interest from NQC to java.



Message has 1 Reply:
  Re: Java version of DiscShooter
 
I think it would be a great idea to have a fixed robot design and a specified behaviour for that robot and then for people to write various applications to make it work. Is this disc shooter design available somewhere? (...) SNip to keep lugnet (...) (22 years ago, 10-Jul-02, to lugnet.robotics.rcx.java)

2 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR