View unanswered posts | View active topics It is currently Wed Aug 24, 2016 5:25 pm






Reply to topic  [ 1 post ] 
Simulation Sentry II Problems 
Author Message
Rookie

Joined: Thu Feb 18, 2016 5:24 pm
Posts: 1
Post 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!!


Thu Feb 18, 2016 5:42 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.