ROBOTC.net forums
http://www.robotc.net/forums/

how detect one thing....then another
http://www.robotc.net/forums/viewtopic.php?f=53&t=2650
Page 2 of 2

Author:  mightor [ Wed Nov 03, 2010 3:32 am ]
Post subject:  Re: how detect one thing....then another

It seems there are at least two of you trying to do this, so I've made a post with some pictures here: [LINK].

Let me know if that helps you.

- Xander

Author:  boxr007 [ Wed Nov 03, 2010 3:39 pm ]
Post subject:  Re: how detect one thing....then another

Yep thats amazing, fantastic help!!! It makes things seem alot more simpler in how to construct the structure of the program. :)

Thanks alot :)

Author:  boxr007 [ Sat Nov 06, 2010 8:00 am ]
Post subject:  Re: how detect one thing....then another

Just to let you know, I have got a working program!! :D

I though I should let you know, since you have helped me alot with it.

So thanks :bigthumb:

Author:  mightor [ Sat Nov 06, 2010 1:35 pm ]
Post subject:  Re: how detect one thing....then another

Could you post it so that others can learn from it?

- Xander

Author:  boxr007 [ Sat Nov 06, 2010 7:54 pm ]
Post subject:  Re: how detect one thing....then another

Of course.
Code:
#pragma config(Sensor, S2,     Back,                sensorSONAR)
#pragma config(Sensor, S3,     Front,               sensorSONAR)
#pragma config(Sensor, S4,     Side,                sensorSONAR)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//


void moveForward()
{
  nMotorEncoder(motorB) = 0;
  nMotorEncoderTarget(motorB) = 600;      // move car forward to bring in level with car it is parking behind.
  motor(motorB) = -45;
  wait1Msec(2500);
}

void park()
{
  nMotorEncoder[motorC] = 0;
  nMotorEncoderTarget[motorC]=180;
  motor(motorC)=75;                     //turn wheels right
  wait1Msec(1000);

  nMotorEncoder[motorB] = 0;
  nMotorEncoderTarget[motorB]=900;
  motor(motorB)=25;
  wait1Msec(2000);                     //move car back

  nMotorEncoder[motorC] = 0;
  nMotorEncoderTarget[motorC]=180;
  motor(motorC)=-75;                    //turn wheels left
  wait1Msec(1000);

  nMotorEncoder[motorC] = 0;
  nMotorEncoderTarget[motorC]=180;
  motor(motorC)=-75;                    //turn wheels left
  wait1Msec(1000);

  nMotorEncoder[motorB] = 0;
  nMotorEncoderTarget[motorB]=350;
  motor(motorB)=35;                     //move car back
  wait1Msec(2000);

  nMotorEncoder[motorC] = 0;
  nMotorEncoderTarget[motorC]=180;
  motor(motorC)=75;                     //turn wheels right
  wait1Msec(1000);

  nMotorEncoder[motorB] = 0;
  nMotorEncoderTarget[motorB]=120;
  motor(motorB)=-35;                    //move car forward
  wait1Msec(1000);

}

task main()
{
  int A;
  int B;
  int totalDistance;
  int distance = 10;
  nMotorEncoder(motorB) = 0;

  while(true)
  {
    motor(motorB) = -35;

  if(SensorValue(S4)>distance)
    {
      A = nMotorEncoder(motorB);
    }

  if(SensorValue(S4)<distance)
    {
      B = nMotorEncoder(motorB);
    }

  totalDistance = B - A;

  if(totalDistance>750)
    {
      moveForward();
      park();
      StopAllTasks();
    }
    else
    {
      motor(motorB) = 0;
    }
  }
}

Author:  boxr007 [ Sat Nov 06, 2010 7:57 pm ]
Post subject:  Re: how detect one thing....then another

If you feel there are parts which could be made more efficient, it would be handy to know too :)

Thanks.

Page 2 of 2 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/