Saturday, November 03, 2007

Mindstorms Roadster Version 1.1

Boy is this Mindstorms thing addictive... I spent last night fixing a bunch of design bugs (I gave up the worm gear steering mechanism shown in the previous post, and adopted a simpler solution).

The chassis is long because my very first intention was to have the brick in the middle of the car (hence the X design, to avoid sagging). But it is more practical to have the brick in the back. And it looks cool, too.

Mechanical issues figured out, I went and downloaded the Bricx Command Center 3.3 and after some tinkering I came up with this code (the car has the touch sensor attached in the back, not shown in the photos).

Although the code is just work in progress, it is already lots of fun to watch to car on the kitchen floor, backing out and steering away to avoid bumping into the furniture!

#include "NXCDefs.h"

#define NEAR 25
#define MIN_BACKOUT 20
#define MAX_BACKOUT 100
#define STEER_ANGLE 20

int angle = STEER_ANGLE;
int backout = MIN_BACKOUT;// backout time

task main()
int i;


while (true)
OnRev(OUT_C, 100); // motor is installed backwards,
// we are going forward

while (SensorUS(IN_4) > NEAR)

OnFwd(OUT_C, 100); // back out at full speed
Wait(50); // wait 50 ms

// steer away from obstacle
RotateMotor(OUT_A, 50, angle);

for (i = 0; i < backout; i++)
// bumped into something while backing?
if (SENSOR_1)
// play sound, then stop
PlayFileEx("! Startup.rso", 1, FALSE);
backout = MIN_BACKOUT;
Off(OUT_C); // stop

angle = -angle; // steer the other way

RotateMotor(OUT_A, 50, angle);

backout += 10; // backout increasingly
if (backout >= MAX_BACKOUT)
backout = MIN_BACKOUT;

No comments: