I was reading an issue of robot magazine (page 48, spring 2007 issue) and a code came up that was used in the Parallax Boe bot that drove through a maze. Would anyone know how to make this code work using C.
Here is the code summary;
Ultrasonic sensor measures the front distance,
Ultrasonic sensor measures the distance to the right,
Ultrasonic sensor measures the distance to the left,
(only one ultrasonic sensor is used and it rotates using a motor)
(How do I store the distances for later use in the code?)
Is distance forward > 7 inches ?
If yes, then move forward 6 inches and go to start.
Is distance right> distance left and > 7 inches?
If yes, then turn right and go to Start.
Is distance left > distance rigght and > 7 inches?
If yes, then turn left and go to start
Otherwise turn 180 degrees and go to start.
This code is fairly complicated. I really need help on the first part(1-3). I am not able to store the distances in the front left and right. Should I stop the ultrasonic sensor after each directional scan and then Start the sensor again after the ultrasonic sensor turns? Should I use any Wait blocks? The rest of the code is a number of If, Else If, and Else statements.
I’ve done this before (a long time ago, and I don’t think it worked for me). It really depends what version of EasyC you have. v1 is no good, and you’ll just have to live with the long code, but if you have v2 or higher (or so I’m told, I don’t have v2 yet), you could make a function and save yourself a lot of code.
I programmed the robot with a similar program and it works. I have one more question. How do you add RX control of 2 more motors while the current code is working? I have tried putting in RX control but I am not able to control the robot with the controller while the code is being executed. Is the Vex microcontroller capable of executing more than one code at a time?
i would personally make some sort of switch, say maybe a rc switcher that can toggle back and forth between the two modes. here is a basic rc switcher, the same kind that i use in almost every single one of my robots:
just ignore the switcher variable, that works with the other functions in this program
Regarding the code that I stated at the beggining of the post, I decide to allow the robot to move forward until the ultrasonic sensor reads less than 10 The only problem is that the code keeps on starting over before the forward moving part finishes. Can you please help, the code is below
int loop = 1;
int f; //forward distance
int l; //left distance
int r; //right distance
The part of the code that does not execute fully before the program starts over is below. In other words the code below is running while the ultrasonic sensor begins scanning again. Can someone please help.
EasyC 1.x or 2.x?? If you attach you EasyC Project, that makes it easer to test and Trouble-Shoot… Especially if I only have 5 Minutes to look at the problem and give you an answer. If you “wrap” your Code in code tags (e.g. code ] / code ]) it will keep the tabbed indenting that was copied from EasyC.
my reasoning was that when the ultrasonic has nothing in its way, it will move slightly forward, and then it will do a complete scan again. i prefer using two ultrasonic sensors and then there is no time wasted scanning.
or like theotherguy said, you could use a while loop.
I tried using the code with the while statement but the robot completely ignored this part of the code, even if the forward direction is greater than 25. I tried putting the GetUltrasonic in fron of the while statement. This allowed the robot to keep driving forward without stopping, even if it is less than 10 ultrasonic units away from the wall. I understand the concept of allowing the robot to drive forward for 1/10th of a second (I already tried this), but I do not want to use this method in my robot do to the inaccuracy and wasted time scanning. Is there anyting else you can do to the code to make the code work?
Thanks, I designed it to be really really really small. There are only 2 metal parts used in the robot, not including the bars, gussets and the beams. I wanted to make something that was small and efficient.
Thanks for the Code Tags, your code is much easer to follow…
What is the Behavior that you are looking for from your Vex??? Start with what you want it to do, then Code that…
As pointed out by theotherguy, if you want to keep moving while the Forward UltraSonic value is Greater Than 25, until it is NOT Greater than 10, you need to keep your program in one area. The While Loop will do that…
Lets break you “program flow” down to see what it does…
int loop = 1;
void main ( void )
//Connect Input Wire to Digital Output 11
//Connect Output wire to Interrupt 1
//Near = 2, Far = 100
StartUltrasonic ( 1 , 11 ) ; // interrupt 1= output label on sensor, DO11=input label on sensor
ALL of the following code is Loop Part, that executes over and over until the power is lost.