Duncan Robot v1
Duncan and I built his first rover-type robot today - he decided that “Alpha Rex’s” time had been and gone, and it was time to build something new. So we sat at the table and mucked about for a bit, knocking out a simple twin-servo skid-steer rover in about an hour.
We then sat down at the NXT software and with some encouragement and some guess work fleshed out a simple rover program. The NXT software isn’t that great for things like this, so we smashed out a better version in NXC.
We then went back to the table and added a button on the backside of the rover, because sometimes the ultrasonic sensor wouldn’t pick up an object (say, a curtain, or on the corner of a wall) and the robot would run up the wall and get stuck. We made it so when the button is pressed, it initiates a program of rolling backwards for 2.5 seconds, turning for 1 second, and then continuing the main routine.
We then also added a sound for fun, on Duncan’s orders.
The code can be found below:
:::c
// Duncan Robot v1
// "explorer" - uses ultrasonic sensor to detect objects in front of it
// and will turn until it clears the object. detects "stuck" situation
// by a push button sensor on the backside of it, will reverse for
// 2.5 secs and then turn ~70 degrees.
task main() {
SetSensorTouch(IN_1);
SetSensorUltrasonic(IN_4);
while (true) {
Wait(250);
// wall in front
if (SensorUS(IN_4) < 15) {
while (SensorUS(IN_4) < 30) {
OnFwd(OUT_B, 75);
OnRev(OUT_C, 75);
}
// this is a file we recorded, comment this out if you like
PlayFileEx("beepboprobot.rso", 100, 0);
Wait(250);
}
// bump button detects, usually, a stuck robot.
// initiate reverse for 2.5 seconds then turn.
if (Sensor(IN_1) > 0) {
OnFwd(OUT_BC, 75);
Wait(2500);
OnFwd(OUT_B, 75);
OnRev(OUT_C, 75);
Wait(1000);
}
// Otherwise, go forward
OnRev(OUT_BC, 75);
}
}
I then drew the whole thing up in Lego Digital Designer, partially because I wanted to play with that software, but also so we would keep the instructions of each robot he builds and see how he progresses as he gets older and cleverer.