Need Programming help

We need help in programing autonomous mode. We need the program to continuously check the input from the sensors. How do I do that without having the whole program in a continuous loop?

If you provide a bit more information, we could help you better.

What programming language are you using?
What sensors are you using?
What purpose are you using the sensors for?

I’ll assume EasyC, since you didn’t say what programming tool you use.

“Timed driving” Autonomous example, is just a sequence of on/wait/off steps

//step1, raise arm for 1 second
 setmotor on;  // to raise the arm;
 wait(1000);   // wait 1
 setmotor off; // stop raising arm
// step2, drive forward for 2 seconds
 setmotor on; // drive forward
 wait(2000);  // wait 2
 setmotor off; //stop

To update “Timed driving” to sensor based, you can just replace each wait() with a while loop waiting on the sensor trigger
Instead of wait(1000) to raise the arm, check that the arm potentiometer is > 200.

while( getsensor(pot) < 200 ){ } // replacement for wait 1

while( wheel encoder < 374 ) { } // replacement for wait 2

Debugging productivity hint: use wireless download and insert print statements to show you what the sensors are reading;

Thanks for your speedy answer!

We are using easy c v4. We are using quad shaft encoders for our two wheel drive and ultrasonic sensors to test the hight of our lifter. Is there a list of the different code for each sensor? Like

[INDENT]while( getsensor(pot) < 200 )

the part in the parentheses, is there a list of those things?

What is the word for limit switches, bump sensors, quad shaft encoders, ultrasonic sensors and light sensors?


The word is “sensors”. In EasyCv4, Function block panel, there are a list of sensors in the “Inputs” section. There are also examples for how to use most of them in the Samples code directory.
var = GetAnalogInput( AnalogPort ); // is used for pot, light sensor, etc
Readability tip: Use program globals to #define Arm_Pot_port1 1
and #define Claw_pot_port2 2
and even #define Arm_up_limit 200
Then your code can look readable like this
while( (var1 = GetAnalogInput( Arm_pot_port1 ) ) < Arm_up_limit ) {
PrintToScreen( “Arm lift wait 1, armpot = %04d\n”, var1);
rather than this version that relies on comments to know the purpose.
while(( var1 = GetAnalogInput( 1) < 200){…}

Encoders and ultrasonics are more complicated because you need to start and preset them, but the GET part is similar.

Ah, very helpful. Thanks. I have used global variables in C++ to make computer games, but I don’t know what their purpose is in easy C or how to apply them. I read a help file and couldn’t figure it out.