View unanswered posts | View active topics It is currently Thu Aug 21, 2014 10:11 pm






Reply to topic  [ 3 posts ] 
Problems with sentry_two in RVW 
Author Message
Rookie

Joined: Mon Apr 08, 2013 12:50 pm
Posts: 10
Post Problems with sentry_two in RVW
Hello!

When I let run my Programm for RVW Curriculum Companion Tables 2.4
for sentry_two there is a strange stop at the 5th big square that I can not
explain myself.

Can you help me?

Here is the code:
Code:
#pragma config(Sensor, S1,     touchSensor,              sensorTouch)
#pragma config(Sensor, S2,     compassSensor,            sensorVirtualCompass)
#pragma config(Sensor, S3,     lightSensor,              sensorLightActive)
#pragma config(Sensor, S4,     sonarSensor,              sensorSONAR)
#pragma config(Motor,  motorA,          gripperMotor,       tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorB,          rightMotor,         tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorC,          leftMotor,          tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/************************************\
|*  ROBOTC Virtual World            *|
|*                                  *|
|*  DO NOT OVERWRITE THIS FILE      *|
|*  MAKE SURE TO "SAVE AS" INSTEAD  *|
\************************************/


void rightTurn(int Turnvelocity, int Turnangle)
{
   nMotorEncoder[leftMotor] = 0;
   while (nMotorEncoder[leftMotor] < Turnangle)
   {
      motor[rightMotor] = -Turnvelocity;
      motor[leftMotor] = Turnvelocity;

   }
   motor[rightMotor] = 0;   //Motoren stoppen, nicht auslaufen!
   motor[leftMotor] = 0;   //Motoren stoppen, nicht auslaufen!
}



task main()
{
   while(true)
   {
         if (SensorValue[sonarSensor]>20 && SensorValue(lightSensor) > 45)
         {
            motor[rightMotor] = 70;
            motor[leftMotor] = 70;
         }
         else
         {
            motor[rightMotor] = 0;
            motor[leftMotor] = 0;
         }

         if (SensorValue(lightSensor) < 45)
         {
            rightTurn(50,165);
         }
   }
}


Wed Jun 19, 2013 11:09 am
Profile
Site Admin
Site Admin
User avatar

Joined: Tue Oct 09, 2012 10:34 am
Posts: 192
Post Re: Problems with sentry_two in RVW
Hi Sigtrygg,
A sometimes inconvenient feature of the sonar sensor in ROBOTC is that it will report a value of -1 if it detects no obstacle. Try changing the condition of your first if statement in main to

Code:
if ((SensorValue[sonarSensor] < 0 || SensorValue[sonarSensor]>20) && SensorValue(lightSensor) > 45)


You can select Robot>>Debugger Window>>Sensors to see the values the sensors are reading in real-time while your programming is running. You can then read through your program, plugging in these values and pretending you are the computer executing the code. This can help you figure out these types of problems.

Cheers,
--Ryan

_________________
Ryan Cahoon
CMU Robotics Academy
RVW Software Developer

Robot Potato Head; Virtual NXT


Wed Jun 19, 2013 11:26 am
Profile
Rookie

Joined: Mon Apr 08, 2013 12:50 pm
Posts: 10
Post Re: Problems with sentry_two in RVW
Thank you very much for the helpful hints!
It works fine now! :D
Here is the code:
Code:
#pragma config(Sensor, S1,     touchSensor,              sensorTouch)
#pragma config(Sensor, S2,     compassSensor,            sensorVirtualCompass)
#pragma config(Sensor, S3,     lightSensor,              sensorLightActive)
#pragma config(Sensor, S4,     sonarSensor,              sensorSONAR)
#pragma config(Motor,  motorA,          gripperMotor,       tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorB,          rightMotor,         tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorC,          leftMotor,          tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/************************************\
|*  ROBOTC Virtual World            *|
|*                                  *|
|*  DO NOT OVERWRITE THIS FILE      *|
|*  MAKE SURE TO "SAVE AS" INSTEAD  *|
\************************************/


void rightTurn(int Turnvelocity, int Turnangle)
{
   nMotorEncoder[leftMotor] = 0;
   while (nMotorEncoder[leftMotor] < Turnangle)
   {
      motor[rightMotor] = -Turnvelocity;
      motor[leftMotor] = Turnvelocity;

   }
   motor[rightMotor] = 0;   //Motoren stoppen, nicht auslaufen!
   motor[leftMotor] = 0;   //Motoren stoppen, nicht auslaufen!
}

void driving(int distance)
{
   nMotorEncoder[motorB]=0;
   while(nMotorEncoder[motorB]<distance)
   {
      if (SensorValue[sonarSensor] < 0 || SensorValue[sonarSensor]>18)
      {
         motor[rightMotor] = 70;
         motor[leftMotor] = 70;
      }
      else
      {
         motor[rightMotor] = 0;
         motor[leftMotor] = 0;
      }
   }
}


task main()
{
   for (int i=0; i<6; i++)//three rounds
   {
      driving(4200);
      wait1Msec(250);
      rightTurn(50,146);
      wait1Msec(250);
      driving(1810);
      wait1Msec(250);
      rightTurn(50,147);
      wait1Msec(250);
   }
}


Thu Jun 20, 2013 4:23 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

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.