Help needed with coding simultaneous movement (EasyC/VEX)

(I really had no idea what to title this thread, but I tried)


I was introduced to VEX robots today in a robotics camp that I am taking at a local community college, and enjoyed myself. When school starts again, I am going to propose a FIRST Challenge team to the science/math department.

Anyway, my question lies in programming with the EasyC software. What my aim was, was to have remote control of the robot while a servomotor ran, autonomously (if thats the correct term).

Basically, I couldn’t get it to work. Either the servo would run, or the remote control would work, but not both at the same time. The way I coded it was by putting both in a “while 1 == 1” loop.

So, if anyone has EasyC experience and can help, it would be appreciated. Even if you know how it’s done in other programs, anything would be helpful. Even some key terms to search for would be helpful because, like I said, I have no idea what the term to search for is.


It would help if you could clarify what you want the servomotor to be doing autonomously. Moving back and forth like a clock, stabbing someone’s finger if they push a bumper button, etc. I’ve got a little experience getting EasyC to move one back and forth and I don’t think it shold be too complicated getting it to do whatever you’d like it to.

basically what i’m trying to do is make the servo move like a clock pendulum, back and forth through the entire range of movement

i want it to start when the vex module is turned on, but if there is any way to link it to run whenever the robot is being actively controlled (i.e., the controls are being manipulated), that would be great, although it seems like it would be very complicated

btw we’re using the tank 2-motor “block” (i guess thats what you’d call it) to control the robot’s movement.

When you mean “actively controlled” do you mean you are driving it, or wether or not the remote is on.

For back and forth you could set an integer to 1 or 0. If the integer equaled 1, it would count up to 255, and when the servo hit 255, the integer would be switched to 0 and cause it to count down back to a servo value of 0, where the integer would be set back to 1 and count up again… repeating…(use ++ and --)

If you wanted this to go just when the robot is being driven (as in currently moving), use an if statement to check the joystick values (if they aren’t centered, you know its being driven)

yes, by actively controlled i mean that it is being moved around.

so basically it will just sit there, and then when someone moves the robot, the servo will start moving, and when the robot stops moving, the servo stops

so cromat, how would i check the joystick position? is it just a 1 or 0 check, or is it more complicated

EDIT - and as for

For back and forth you could set an integer to 1 or 0. If the integer equaled 1, it would count up to 255, and when the servo hit 255, the integer would be switched to 0 and cause it to count down back to a servo value of 0, where the integer would be set back to 1 and count up again… repeating…(use ++ and --)

i really have no idea how to even do that.

the manual that came with the program, or at least the one we recieved, was way too basic.

Alrighty. First off, it should automagically not move when the RC is off or unconnected. I believe everything goes to neutral and center when the RC is off unless autonomous is enabled. At any rate, your options are to use a timer based solution or some kind of pseudo-loop.

start a timer at the beginning of your program before the while loop.
get its value every while loop and assign it to “time” for instance.
toss in an if statement and make the condition time > ### (however many milliseconds you want between swings one side to the other)
inside that if one, preset the timer back to 0, then set the servo PWM to one way or another. use an if-else and have it based on which way the servo currently is.
This will work and is basically how I was timing the movement of my slapdash ball chambering servo. The problem I was have was that my code took forever to get through the while (1) loop. about 200 ms. so I couldn’t look for time slices smaller than that. Which frustrated my attempts to shoot balls as fast as possible.

Pseudo-for loop:
have a variable called “i” put an assignment for i=(i+1)%## in your while loop. ## is the number of loops through your while loop before it rolls over, so it’s the period.
put in if i == whatever statements and set the servo PWM here.
advantage of this, is you can make it move to intermediate positions at every value of i. disadvantage is I’ve no idea what the timing of that while(1) loop is, so you’ll be sort of guessing how fast it’s going.

Using that idea above, to modify the two loops I’ve suggested:
Timer: Stop the timer if the robot’s not moving, start the timer if the robot is moving.
Pseudo: put an if statement around the assignment, so it only runs if the robot is running.

I have attached code that should work. You will probably need to modify all of the Rx inputs and PWM outputs.
If any one sees a problem with this code, you are probably right . :smiley:
BTW there is no overflow protection, which might happen, but I am assuming you don’t need really precise servo control? When you stop moving the robot the servo stops in place, but when you start moving it again, the servo moves to its positive limit and then starts the back and forth movement again.

code_example.pdf (24 KB)

code_example.pdf (24 KB)

Yea, there appear to be some syntactical (things written wrong) and symantical (things done wrong). The simplest thing is that the incrementing and decrementing (is that a word?) of pendu_speed dont really do what they are supposed to. Instead incrementing or decreasing you assign the value of 1 or -1 to pendu_speed. It should be pendu_speed++ or pendu_speed–.

The next problem is with this statement

pendu_servo = pendu_speed + pendu_servo

the value of pendu_servo could be 250 in one loop and the next time around, the joystick could be nuetral but because pendu_servo already has the value of 250, it will continue to be 250.

You could probably fix that by moving the code block setPwm(3, pendu_servo) into the else statement. Then change the if statement to to setPwm(3,127). That way the if the statement evaluates to true (meaning joystick is nuetral), the pwm will be dead. However, if it evaluates falsely, it will be assigned to a value.

And in terms of the actual servo movement, I cant really help because I have actually never worked with servos.

And my corrections of your mistakes could also be mistakes.