My school has entered in a robotics competition. The competition is called botball (botball.org). You have 8 weeks to build and program your robot, and then you compete. Every week you must document everything done on the robot, and what every single person did. The competition this year is really difficult. Your robot has to pick up certain colored balls, and put them in different colored cups, etc. Your robot must only go when the start light goes on, if it leaves early you are DQ. Also, there is a 90s time limit. The robot must stop moving before the time limit. If you go over the time limit, your team is DQ.
The robot is controlled by a GameBoy Advance. The programs are written in C, and compiled into a format that the firmare on the GBA rom can read. The robot has a color camera, and up to I think 4 servos, and numerous digital inputs, and much more! I am the co-programmer on the robotics team. The head programmer (who happens to be my friend) went to a two-day conference to learn how to program the robot with all of the other people regionally that are doing the competition. One person on the robotics team is good at filming movies, but not so good at programming. Another kid on the robotics team is EXCELLENT at building anything that has moving parts. All of the other people on our robotics team are also my friends, which is very good, except when we start screwing around when we get bored!
Anyway, although no-one can tell what this code does, I am just going to post it anyway. I have run it on the robot simulator on my computer (it allows you to simulate robot movements and such). I really hate how in the compiler, floats are truncated to longs. So, when I convert a float to a long for the motor when the robot turns, it ends up not turning the correct amount. This is what robotic arms are for, to reach the stuff where you can't move! :P This is a VERY short code, because all it does is move around. The final robot code should be about 10x as much as what is below, I would guess.
The robot is controlled by a GameBoy Advance. The programs are written in C, and compiled into a format that the firmare on the GBA rom can read. The robot has a color camera, and up to I think 4 servos, and numerous digital inputs, and much more! I am the co-programmer on the robotics team. The head programmer (who happens to be my friend) went to a two-day conference to learn how to program the robot with all of the other people regionally that are doing the competition. One person on the robotics team is good at filming movies, but not so good at programming. Another kid on the robotics team is EXCELLENT at building anything that has moving parts. All of the other people on our robotics team are also my friends, which is very good, except when we start screwing around when we get bored!
Anyway, although no-one can tell what this code does, I am just going to post it anyway. I have run it on the robot simulator on my computer (it allows you to simulate robot movements and such). I really hate how in the compiler, floats are truncated to longs. So, when I convert a float to a long for the motor when the robot turns, it ends up not turning the correct amount. This is what robotic arms are for, to reach the stuff where you can't move! :P This is a VERY short code, because all it does is move around. The final robot code should be about 10x as much as what is below, I would guess.
#use "iROBOsim.ic"
#use "botball.ic"
void main()
{
iROBOinit(RULERWORLD); //rsim - use RULERWORLD world file
iROBOtrail=1; //rsim - use trail
//wait_for_light(2); //Wait for the light sensor port 2
while (a_button() == 0) {}; //Wait for a_button instead of light sensor for sim
sleep(0.25); //Wait for .25s just so that we don't leave early if something goes wrong
shut_down_in(89.5); //Shut it down in 89.5s, Most important function!
JoeProg(); //Start the class that does runs processes
}
void JoeProg()
{
printf("Robot will shut down in 89.5s");
printf("Start processes...");
start_process(mvvm()); //Start mvvm() function (controls movements) as a process
printf("Movement process started!");
}
void mvvm()
{
gofwd(30.0, 1100);
turn(-90.0);
gofwd(30.0, 1100);
turn(-90.0);
gofwd(30.0, 1100);
turn(-90.0);
gofwd(30.0, 1100);
kill_process(mvvm()); //Kill this process so it doesnt loop
}
void gofwd(float dist, int speed)
{
//Approximation of pi
float pi = 3.14159265;
//Diameter of wheels (cm)
float wh_dia = 5.6;
//diameter & distance -> ticks
float ticks = dist / ((pi * wh_dia)/1100.0);
//move both motors fwd specified tics
rsim_mrp(0, speed, (long)ticks);
rsim_mrp(1, speed, (long)ticks);
rsim_bmd(0); rsim_bmd(1);
}
void turn(float deg)
{
//Approximation of pi
float pi = 3.14159265;
//Diameter of wheels (cm)
float wh_dia = 5.6;
//Wheelbase of robot (cm)
float wb = 12.0;
float r = 6.0;
//Calculate distances each wheel must travel
float R_Dist = ((deg/360.0) * (pi * wb) / ((pi * wh_dia)/1100.0));
float L_Dist = R_Dist - (2.0 * R_Dist);
rsim_mrp(0, 1100, (long)R_Dist);
rsim_mrp(1, 1100, (long)L_Dist);
rsim_bmd(0); rsim_bmd(1);
}