Our new robot design with treads. |
#pragma config(Sensor, S2, FloorColor, sensorCOLORFULL)
#pragma config(Motor, motorB, RightWheel, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorC, LeftWheel, tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
void color_read();
void white_task(int forward_speed);
void black_task(int reverse_speed);
int read_output;
task main()
{
int universal_speed = 25;
while(1 == 1)
{
color_read();
switch(read_output)
{
case 6 :
white_task(universal_speed);
break;
case 1 :
black_task(universal_speed);
break;
}
}
}
void color_read()
{
bool value_ready = false;
while(!value_ready)
{
int A = SensorValue[FloorColor];
int B = SensorValue[FloorColor];
int C = SensorValue[FloorColor];
if(A == B && B == C && C == A)
{
read_output = C;
value_ready = true;
}
else
{
value_ready = false;
}
}
}
void white_task(int forward_speed)
{
motor[RightWheel] = forward_speed;
motor[LeftWheel] = forward_speed;
}
void black_task(int reverse_speed)
{
motor[RightWheel] = 0 - reverse_speed;
motor[LeftWheel] = 0 - reverse_speed;
}
No comments:
Post a Comment