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

Simulation Sentry II Problems
http://www.robotc.net/forums/viewtopic.php?f=11&t=13403
Page 1 of 1

Author:  droberts6262 [ Thu Feb 18, 2016 5:42 pm ]
Post subject:  Simulation Sentry II Problems

We are having trouble with solving this problem and could use some help. In this task we are to continuously go around an object as a sentry. If we come to an object that is observed using our ultrasonic sensor, we are to stop until it is removed. Once removed, we are supposed to continue our "sentry duty". Our robot will stop, but only after it makes a turn. If an object is placed in the way during a "straight" portion, it will not stop. If it is placed in front of the robot after to turns, it stops and continues the sentry duty. So it sort of works, but overall it does not.

We think that because of the way that we wrote the code, it has to go through the straight portion and the turn before it can do anything else. We have tried many different things. We are at a loss. Any help would be appreciated.

Here is the code:

Code:
#pragma config(Sensor, dgtl1,  rightEncoder,   sensorQuadEncoder)
#pragma config(Sensor, dgtl3,  leftEncoder,    sensorQuadEncoder)
#pragma config(Sensor, dgtl8,  sonarSensor,    sensorSONAR_inch)
#pragma config(Motor,  port1,           rightMotor,    tmotorVex269, openLoop, reversed)
#pragma config(Motor,  port10,          leftMotor,     tmotorVex269, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

//VOID STATEMENTS =================================================================================

      //STRAIGHT
void moveStraight(int encoderCount)
{
      SensorValue[rightEncoder] = 0;
       SensorValue[leftEncoder] = 0;

    while(SensorValue[rightEncoder] < encoderCount)
  {
      if(SensorValue[leftEncoder] > SensorValue[rightEncoder])
      {
         motor[rightMotor] = 63;
         motor[leftMotor] = 47;
     }
     if(SensorValue[rightEncoder] > SensorValue[leftEncoder])
     {
        motor[rightMotor] = 55;
        motor[leftMotor] = 63;
     }
     if(SensorValue[leftEncoder] == SensorValue[rightEncoder])
     {
        motor[rightMotor] = 63;
        motor[leftMotor] = 48;
     }
  }
}

      //RIGHT

void moveRight(int encoderCount)
{
      SensorValue[rightEncoder] = 0;
       SensorValue[leftEncoder] = 0;

  while(SensorValue[leftEncoder] < encoderCount) //475!!!!!!
   {
    motor[rightMotor] = -63;
    motor[leftMotor] = 60;
   }

      motor[leftMotor] = 0;
     motor[rightMotor] = 0;
     wait1Msec(500);
}

task main()
{

   SensorValue[rightEncoder] = 0;      //Reset encoders to zero
  SensorValue[leftEncoder] = 0;

   while(1 == 1)                     //while true
   {
      if(SensorValue[sonarSensor] > 7)   // when the robot is greater than 7cm away from an object
      {
         moveStraight(1225);      //straight for the encoder count 1225 then turn right for the encoder count 450

         moveRight(450);
      }
      else                  // if it is closer than 7cm
      {
         motor[leftMotor] = 0;      //stop
         motor[rightMotor] = 0;
      }
   }
}



Thanks so much!!

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