![]() |
Running a motor for a set time in auton
Suppose that I need to run relay1 for 500 milliseconds. I have tried code like this in roboemu1.11.
if (auton_mode = 1) then relay1_fwd = 1 pause 500 relay1_fwd = 0 endif Shouldn't that turn on relay 1, wait 500 milliseconds, then turn it off? Since this doesn't work how would you do it? Thanks |
That won't work. You'll have to program a timer in. The stamp cycles about once every 26 milliseconds.
Time var byte Timeover var bit If timeover = 1 then timeroff Time = time + 1 + delta_t 'make sure to turn delta_t on, ' otherwise this won't work relay1_fwd = 1 If time < 20 then dont_turn_off relay1_fwd = 0 Timeover=1 dont_turn_off: timeroff: 'PBasic takes inputs, and sends outputs accordingly once every 'cycle. That is why your code doesn't work. 'I think the pause just pauses the cycle. I haven't ever used it. 'Good luck on your programming! Feel free to ask other any other 'questions. |
Jeff_Rice's code should work for you. If you want some more info on why the original code wouldn't work, read on. Otherwise, just ignore the rest of this.
Here goes: 1. None of the variable names actually mean anything. For example, you could rename relay1_fwd to relay7_rev and as long as you updated the aliases correctly, the Stamp wouldn't know the difference. 2. Just setting a variable won't change the motor itself. In fact, setting the variables are just a matter of convience and allow for more complex processing. 3. The motors are actually set by the values passed to the SEROUT command. Since the original code never reaches a SEROUT between the relay1_fwd = 1 and the relay1_fwd = 0, the relay will never know the difference. Furthermore, if you don't do a SEROUT at least once every 5 loops (that's ~125ms), you'll get a Basic Run Error. RoboEmu is a little more forgiving and will only complain after 1s which is probably why you didn't get any actual errors. |
thanks
|
I would also warn you to avoid doing anything that will tie up the robot in a loop -- even one that includes a serout command. OR, let me say that all loops MUST include a test for autonomous mode bit. If you get in a pause or a loop and do not test for the end of autonomous mode, you will have a robot and a human, but no loving nurturing relationship...
Eric |
Also something very important is having a SERIN command just before your autononomous code. This is very important because you need to get the mode every time it goes through the loop (you won't get control from the robot if you don't.)
|
| All times are GMT -5. The time now is 04:27. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi