http://www.aplu.ch/dev/nxtrobot.jpg
Is there a general interest and what are your suggestions/proposals?
Aegidius
PS: Here a sample program with one NXT brick
- Code: Select all
// RobotEx1.java
// One robot with two motors
import ch.aplu.nxt.*;
public class RobotEx1
{
RobotEx1()
{
// Create robot
NxtRobot roby = new NxtRobot("NXT");
// Create two motors
Motor motA = new Motor(MotorPort.A);
Motor motB = new Motor(MotorPort.B);
// Assemble motors into robot
roby.addPart(motA);
roby.addPart(motB);
// Connect PC and robot
roby.connect();
// Use motors
motA.forward();
motB.forward();
// Disconnect
roby.disconnect();
}
public static void main(String[] args)
{
new RobotEx1();
}
}
Here a sample program with two bricks:
- Code: Select all
// RobotEx2.java
// Two robots with each two motors
import ch.aplu.nxt.*;
public class RobotEx2
{
RobotEx2()
{
// Create robots
NxtRobot john = new NxtRobot("NXT");
NxtRobot jaye = new NxtRobot("NXT5");
// Create four motors
Motor motA = new Motor(MotorPort.A);
Motor motB = new Motor(MotorPort.B);
Motor motC = new Motor(MotorPort.A);
Motor motD = new Motor(MotorPort.B);
// Assemble motors into robots
john.addPart(motA);
john.addPart(motB);
jaye.addPart(motC);
jaye.addPart(motD);
// Connect PC and robots
john.connect();
jaye.connect();
// Use motors
motA.forward();
motB.forward();
motC.setSpeed(50);
motD.setSpeed(50);
motC.forward();
motD.backward();
// Disconnect
john.disconnect();
jaye.disconnect();
}
public static void main(String[] args)
{
new RobotEx2();
}
}
