apr 25
lego robots ?
Things to try:
- I haven't tried to compile this yet (gulp) ...
- load and test a simpler version that makes different beeps depending on button pushed first
- go for the gusto and try this one ...
/// Send a number.
import josx.rcxcomm.*;
import josx.platform.rcx.*; // includes Sound object
import java.io.*;
public class TestRCXComm {
public static RCXPort port = new RCXPort();
public static int magicNumber = 7;
public static void nBeeps(int n){
for (int i=0; i<n; i++)}{
Sound.beep();
}
wait(1.0);
}
public static void wait(double seconds){
try {
Thread.sleep((long)(seconds/1000.0));
}
catch (InterruptedException ie){
}
}
public static void send(int data){
nBeeps(1); // getting ready to send
try {
OutputStream os = port.getOutputStream();
os.write(data);
os.flush();
}
catch (IOException ioe) {
Sound.buzz(); // something bad happened
}
nBeeps(2); // sent.
}
public static void receive(int expected){
InputStream is = port.getInputStream();
int data = is.read();
if (data == expected){
Sound.beepSequence();
}
else {
nBeeps(1);
}
}
public static void main(String [] args) {
while (true){
if (Button.VIEW.isPressed()){
Sound.beepSequence(); // yes, I'm alive
}
else if (Button.PRGM.isPressed()){ // send or recieve
// Comment one of these two lines out,
// depending on whether you're loading it into
// the sender or reciever.
// Timing? Is receive a blocking call??
send(magicNumber); // beep <sending> beep beep
receive(magicNumber); // success: melody; failure: one beep
}
}
Smart::Comments and some perl goodies
CPAN
perlmonks.org
TeRK
- http://www.terk.ri.cmu.edu/index.php
- carnegie melon lab with java open source software to run robots.
- includes intro CS course using 'em
- includes various "recipes" for building the 'bots from online available parts, starting at around $500/bot
fablab