Saturday, July 9, 2011

July 9, 2011 Practice

Our new robot design with treads.
Today Ian and I worked on two different things. I worked on programming code to complete tasks based on colors detected with our robot's color sensor. The program also used logical sequences to run the code. Ian worked on improving the robot by giving it treads. After Ian left early, I added sensors to the robot and got it working with some of our previous code. I personally learned a lot of new logic statements for the RobotC language. This was my most enjoyable and productive meetings yet. I can not wait to see what the future holds for our RobotC adventures. The full program I made at today's practice is below:




#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