Friday, June 5, 2009

Robot Competition (day two)

We got to see other people's wheelchair's and defenders today. While all seemed to mostly work, some were more impressive than others. Specifically the only group that decided to brave the ramp did as good a job as possible with the not-so-accurate light sensors. The main reason I mention them is because our defender was able to stop them on the ramp with the reaching arm. Of course, the defender required a bit of modifying (wheel counter-balances removed and used as stilts, and the tread removed), but it worked in stopping them.

All in all our robots were successful. The code posted below is not the final code, as we made a few tweaks to the navigating code and the steering check code, but it shows the direction that we were going. The final code is stuck on the engineering computer which we were unable to get to. The code posted below also did not parse well since blogger uses HTML code to enter the posts, so some of it got parsed. Most of it is there though.

It was sad to see our robot go, but we'll have a video up of it navigating the course soon enough.

Here's to a great year in Engineering 100.

(P.S. We'd like to give a special thanks to Snapple!)

Wednesday, June 3, 2009

Robot Competition

Well we completed the competition today. Our robot navigated the course with ease until it reached the defenders which snagged our robot both times. Overall I'd call it a success though since I didn't see any other group get past the defenders. The program worked exactly like it was supposed to, and was even off a little bit from where it should have been but still managed to navigate the course. This shows the robustness of the robot.

The steering calibration worked perfectly and there were no problems with getting stuck (steering or wheels).

We also got to test our car which, as I would've imagined (because the program was so simple), worked fine and didn't stop on the crosswalk. We didn't have a chance to test our defender because everyone kept needing to replace their batteries so we ran out of time, but we'll do that tomorrow.

Monday, June 1, 2009

Robot programs

Here is the wheelchair program, complete with steering check...
It goes with this robot

Wheelchair Robot Program, controls above pictured robot     Copyright (C) 2009  Jordan Lange      This program is free software: you can redistribute it and/or modify     it under the terms of the GNU General Public License as published by     the Free Software Foundation, either version 3 of the License, or     (at your option) any later version.      This program is distributed in the hope that it will be useful,     but WITHOUT ANY WARRANTY; without even the implied warranty of     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     GNU General Public License for more details.      You should have received a copy of the GNU General Public License     along with this program.  If not, see 
#define engine_main OUT_A;
#define engine_steer OUT_B;
#define sensor_left SENSOR_1;
#define sensor_right SENSOR_3;
#define sensor_steering SENSOR_2;

int turning = 0;

task main() {
SetSensor(SENSOR_1, SENSOR_TOUCH);
SetSensor(SENSOR_2, SENSOR_TOUCH);
SetSensor(SENSOR_3, SENSOR_TOUCH);
SetSensorMode(SENSOR_1, SENSOR_MODE_RAW);
SetSensorMode(SENSOR_2, SENSOR_MODE_RAW);
SetSensorMode(SENSOR_3, SENSOR_MODE_RAW);
SetPower(OUT_A, 99); // Main power at max
SetPower(OUT_C, 99); // Main power at max
SetPower(OUT_B, 3); // Steering power at 3

OnFwd(OUT_A); // Turn on engines
OnFwd(OUT_C);
// Check for bumping into the walls...
start steering_check;
// Navigate the course
start navigate_course;
}

task steering_check() {
while (true) {
if (turning != 1) {
// Make sure the steering is straight
if (SENSOR_2 > 45) {
// Turn power off while correcting the steering
int x = OutputStatus(0);
int y = OutputStatus(2);
if (x > 0) {
Off(OUT_A);
Off(OUT_C);
}
// Steering is off, set it all the way to the left
SetPower(OUT_B, 7);
OnRev(OUT_B);
Wait(20);
Off(OUT_B);
SetPower(OUT_B, 3);
// Bring the steering back to center
int timeout = Timer(0);
int timeoutCounter = 0;
int power = 3;
while (true) {
if (Timer(0) > timeout + 30) {
// Try again...
// set steering all the way to the left again
SetPower(OUT_B, 7);
OnRev(OUT_B);
Wait(20);
Off(OUT_B);
if (timeoutCounter > 4) {
// Failsafe, wheels are STUCK
power++;
}
SetPower(OUT_B, power);
// Reset timeout
timeout = Timer(0);
timeoutCounter++;
}
if (SENSOR_2 <>
break;
OnFwd(OUT_B);
Wait(1);
Off(OUT_B);
}
// Turn the power back on
if (x > 0) {
OnFwd(OUT_A);
OnFwd(OUT_C);
}
// Steering is aligned, yay!
repeat (5) { PlaySound(SOUND_CLICK); }
}
}
}
}

task navigate_course() {
OnFwd(OUT_A);
OnFwd(OUT_C);
Wait(1150);
Off(OUT_A);
Off(OUT_C);
repeat(10) {
SendMessage(1);
}
ClearMessage();
until (Message() == 2);
OnFwd(OUT_A);
OnFwd(OUT_C);
// start banking to the right a little bit so it hits the walls
turning = 1;
turn(5);
Wait(500);
turn(-4);
until (SENSOR_1 <= 150 && SENSOR_3 <= 150);
// Hit the far wall, reverse and then turn left
OnRev(OUT_A);
OnRev(OUT_C);
Wait(700);
OnFwd(OUT_A);
OnFwd(OUT_C);
// hard left to cross stairs
turn(-12);
Wait(720);
turn(8); // straighten steering up a bit
Wait(100);
turning = 0;
// The first wall it hits, turn to the left
// Should be in a position where that's useful
until (SENSOR_1 <= 150 || SENSOR_3 <= 150);
reverse_turn(13, 180);
repeat (5) { PlaySound(SOUND_CLICK); }
// Defender mode (default mode)
while (true) {
if (SENSOR_1 <= 200) {
reverse_turn(-13, 180);
}
if (SENSOR_3 <= 200) {
reverse_turn(13, 180);
}
}
}

void turn(int time) {
if (time <>
OnFwd(OUT_B);
Wait(-1 * time);
Off(OUT_B);
} else if (time > 0) {
OnRev(OUT_B);
Wait(time);
Off(OUT_B);
}
}
void reverse_turn(int time, int back_delay) {
turning = 1;
if (time <>
OnRev(OUT_A);
OnRev(OUT_C);
OnFwd(OUT_B);
Wait(-1 * time);
Off(OUT_B);
Wait(back_delay);
Off(OUT_A);
Off(OUT_C);
} else if (time > 0) {
OnRev(OUT_A);
OnRev(OUT_C);
OnRev(OUT_B);
Wait(time);
Off(OUT_B);
Wait(back_delay);
Off(OUT_A);
Off(OUT_C);
}
OnFwd(OUT_A);
OnFwd(OUT_C);
turning = 0; // Let the steering check take care of setting the steering back to straight
}

Next up is the Car program...
It is this robot, but the extending arm will be removed and the brick turned to the side to allow the wheelchair coming over the ramp to communicate with it
Car Robot Program, controls above pictured robot     Copyright (C) 2009  Jordan Lange      This program is free software: you can redistribute it and/or modify     it under the terms of the GNU General Public License as published by     the Free Software Foundation, either version 3 of the License, or     (at your option) any later version.      This program is distributed in the hope that it will be useful,     but WITHOUT ANY WARRANTY; without even the implied warranty of     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     GNU General Public License for more details.      You should have received a copy of the GNU General Public License     along with this program.  If not, see 
task main() {
SetPower(OUT_A, 7);
SetSensor(SENSOR_3, SENSOR_LIGHT);
ClearMessage();
while (Message() != 1) {
OnFwd(OUT_A);
Wait(500);
OnRev(OUT_A);
Wait(500);
}
if (SENSOR_3 <= 38) {
Toggle(OUT_A);
until (SENSOR_3 >= 45);
Wait(200);
Off(OUT_A);
}
Off(OUT_A);
}

And last is our defender program...

Defender Robot Program, controls car robot pictured above, but with a different purpose     Copyright (C) 2009  Jordan Lange      This program is free software: you can redistribute it and/or modify     it under the terms of the GNU General Public License as published by     the Free Software Foundation, either version 3 of the License, or     (at your option) any later version.      This program is distributed in the hope that it will be useful,     but WITHOUT ANY WARRANTY; without even the implied warranty of     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     GNU General Public License for more details.      You should have received a copy of the GNU General Public License     along with this program.  If not, see 
task main() {
SetPower(OUT_A, 7);
OnRev(OUT_A);
Wait(500);
Off(OUT_A);
SetPower(OUT_C, 5);
OnFwd(OUT_C);
Wait(200);
Off(OUT_C);
}

This program extends this arm (not Chun's arm):