Author:  f6e9a [ Tue Nov 12, 2013 12:50 pm ]

Is it possible for me to program a robot to reach a certain destination, but stop for objects in its path until they are removed in a loop. It is import that the robot continues from the point it left off at.
 Code:#pragma config(Sensor, S3,     ,               sensorSONAR)//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//task main(){while (true)   {       if (SensorValue(sensorSONAR)>25)       {          motor[motorB] = 100;      //straight          motor[motorC] = 100;          wait10Msec (1);                    motor[motorB] = 0;       //turn left          motor[motorC] = 100;          wait10Msec (1);                              motor[motorB] = 100;     //straight          motor[motorC] = 100;          wait10Msec (1);                              motor[motorB] = 0;            // stop          motor[motorC] = 0;          wait10Msec (1);                 }   else     {        motor[motorB] = 0;  // halt        motor[motorC] = 0;    }   }}

 Author: JohnWatson [ Thu Nov 14, 2013 12:54 pm ] Post subject: Re: Stop and continue program. This is definitely doable; in fact, it's a very similar challenge to the Sentry Simulation 3 in the ROBOTC Curriculum for TETRIX and LEGO MINDSTORMS To start, let's plan out some psuedocode; list, in order, exactly what you want the robot to do step-by-step. This will help us outline the actions we want the robot to make and the order we want them to be executed in. Once we have that, we can start determining the best way to have the robot perform those actions, the coding tools we can use to control those actions (how long/how far the robot should move for, when to stop, when to turn, etc), and finally the exact lines of code to use for each action.

 Author: f6e9a [ Mon Nov 18, 2013 11:55 am ] Post subject: Re: Stop and continue program. Sorry for the late replay but.Psuedocode go straight 3 ft. turn left 90 degrees.continue 4 ft. turn right 90 degrees.Stop.also if something is in its path is it possible for the robot to produce a beeping sound. Thanks for all your help I understand feet is not a variable and we will most probably use the wait10Msec.

 Author: f6e9a [ Wed Nov 27, 2013 12:46 pm ] Post subject: Re: Stop and continue program. someone pls help me or show me an example code. plsI am willing to learn, someone help.

 Author: JohnWatson [ Wed Dec 04, 2013 1:23 pm ] Post subject: Re: Stop and continue program. Have you gone through the ROBOTC Curriculum for TETRIX and LEGO Mindstorms yet? It will walk you through the steps needed to program this challenge, step by step; you may have to calculate the distance the robot needs to travel for this particular challenge, but once you have completed the Sentry Simulation 3 challenge this should be fairly easy to work out.

 Author: f6e9a [ Mon Dec 09, 2013 1:29 pm ] Post subject: Re: Stop and continue program. (URGENT) (PLEASE HELP) Yes, our teacher had us go through the basics, but i am still having trouble understanding.

Author:  f6e9a [ Tue Dec 10, 2013 1:12 pm ]

My exact problem is.

If i put the code in a while loop, making the robot lets say go in a square as long as nothing is in let's say 5 cm of the sonar sensor. If something comes in it's way it will stop and end the loop.

I could use a function.

I just don't understand what command or variable to use to get the robot to recall where it left off and continue from there.
 Code:task main(){while (true){   if (SensorValue(sonarSensor)>20)   {                  motor[motorB] = 10;              motor[motorC] = 10;         wait1Msec (5000);         motor[motorB] = 10;         motor[motorC] = 0;         wait1Msec (5000);         }else{   motor[motorC] = 0;   motor[motorB] = 0;}}}

Author:  MHTS [ Tue Dec 10, 2013 2:51 pm ]

f6e9a wrote:
 Code:task main(){    while (true)    {        if (SensorValue(sonarSensor)>20)        {            motor[motorB] = 10;            motor[motorC] = 10;            wait1Msec (5000);            motor[motorB] = 10;            motor[motorC] = 0;            wait1Msec (5000);        }        else        {            motor[motorC] = 0;            motor[motorB] = 0;        }    }}

 Code:while (true){    Drive(distance, power);    Turn(angle, power);}

Then the next step is to figure out how to write those two functions so that it will also check for obstacles. Basically, the drive function should say "while not reaching the distance, if no obstacle in front keep driving, otherwise stop".
 Code:void Drive(int distance, int power){    //    // Adjust power so that it is only negative if distance is negative.    //    power = abs(power);    if (distance < 0)    {        power = -power;    }    //    // reset encoders.    //    nMotorEncoder[motorB] = 0;    nMotorEncoder[motorC] = 0;    //    // while not reaching target.    //    while (abs(nMotorEncoder[motorB] + nMotorEncoder[motorC])/2 < distance)    {        //        // Check for obstacle.        //        if (SensorValue[sonarSensor] > 20)        {            motor[motorB] = power;            motor[motorC] = power;        }        else        {            motor[motorB] = 0;            motor[motorC] = 0;        }        wait1Msec(10);    }}

So now do the same for turning. The code is almost identical except for checking the encoders for turned angle instead of distance.
 Code:void Turn(int angle, int power){    //    // Adjust power so that it is only negative if angle is negative.    //    power = abs(power);    if (angle < 0)    {        power = -power;    }    //    // reset encoders.    //    nMotorEncoder[motorB] = 0;    nMotorEncoder[motorC] = 0;    //    // while not reaching target.    //    while (abs(nMotorEncoder[motorB] - nMotorEncoder[motorC])/2 < angle)    {        //        // Check for obstacle.        //        if (SensorValue[sonarSensor] > 20)        {            //            // Assuming motorB is the left motor and motorC is the right motor.            //            motor[motorB] = power;            motor[motorC] = -power;        }        else        {            motor[motorB] = 0;            motor[motorC] = 0;        }        wait1Msec(10);    }}

Author:  f6e9a [ Wed Dec 11, 2013 11:13 pm ]

Thanks, what you said makes perfect sense.
I understand the code, but what i don't understand is how you are declaring 2 parameters per function. (Angle, Power, Distance.) and for me to declare these variables i would need to do it before the functions right?
like so.

 Code:int distance;int power;int angle;

before the starting of the code, but would i enter the actual integers here or inside the Task Main after the functions are called forth?

Sorry kind of a newb. Thanks for all the help though.

Author:  MHTS [ Thu Dec 12, 2013 1:52 am ]