Skip to main content

NEED HELP WITH JAVA PROGRAM

1 reply [Last post]
jarry909
Offline
Joined: 2008-05-14
Points: 0

well... i really need help writing out steps using the LEGO MINDSTORMS RCX Robots to make a program... or simple JAVA

basically the program needs to only be these requirements... (doesnot matter how it is made using LEGO MINDSTORMS RCX Robots):
-needs to start off by looking to see where the color black is by turning 360 around
-once the robot finds the black then it should start to follow the black color
-now all the robot must do is to keep on the black trail and only follow the black color... but for a robot you have no idea the shape of the black tape (although i can physically see it, the robot much stay on the black tape) if the black turns right it must turn right if it is curved the robot must curve too

i need a lot of help, thanks...

that's all it basically has to do sense black and follow the black tape on its own, with only the run button pressed...

this can be done on java too... but it should be very simple...

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexsch
Offline
Joined: 2007-07-12
Points: 0

You can start writing your program with the following draft:

[code]
import javafx.ui.*;
import javafx.ui.canvas.*;
import javafx.animation.*;

import java.lang.System;

class Robot extends CompositeNode {
public attribute x: Number;
public attribute y: Number;

public function move () {
System.out.println("Define moving algorithm here!");
x++;
y++;
}

public function composeNode(): Node{
return Group{
content:[
Circle{ cx: bind x, cy: bind y, radius: 30 stroke: Color.GRAY},
Text{ x: bind x - 20, y: bind y, content: "Robot" }
]
}
}
}

class ColorPoint extends CompositeNode {
public attribute x: Number;
public attribute y: Number;
public attribute color: Color ;

public function composeNode(): Node{
return Circle{ cx: bind x, cy: bind y, radius: 5, fill: color }
}
}

var robot = Robot{ x: 100, y: 100 };

var timeline = Timeline {
keyFrames: KeyFrame {
time: 0.3s
action: function() { robot.move(); }
}
repeatCount: java.lang.Double.POSITIVE_INFINITY
}

timeline.start();

Frame{
width: 300
height: 300
content: Canvas{
content: [
robot,
ColorPoint{ x: 200, y: 200 color: Color.BLACK}
]
}
visible: true
}

[/code]