electronic speed controller
Chriroz
Posts: 8
I'm using a pbasic code on a basic stamp2 to control my robot.
I'm trying to control an "electronic speed controller" to control my engine (yes, thats right :P)
therefore i use this peace of code:
if i remove the first if (and the end if) then the engine will drive else not...
it uses the code like it should (i checked with a debug) but it doesnt drive...
is it possible that an if in an if does strange things?
i attached the full (still unfinished) code for the robot
what can it be??
edit: resm was larger than 1500 when i tested
Post Edited By Moderator (Chris Savage (Parallax)) : 12/9/2006 8:33:13 PM GMT
I'm trying to control an "electronic speed controller" to control my engine (yes, thats right :P)
therefore i use this peace of code:
IF resm > 100 THEN 'if i remove this and the "end if" it works IF resm > 1500 THEN f = 800 'go forward ELSEIF resm < 1400 THEN f = 710 'go backward ENDIF ENDIF drive: PULSOUT 13, f
if i remove the first if (and the end if) then the engine will drive else not...
it uses the code like it should (i checked with a debug) but it doesnt drive...
is it possible that an if in an if does strange things?
i attached the full (still unfinished) code for the robot
what can it be??
edit: resm was larger than 1500 when i tested
Post Edited By Moderator (Chris Savage (Parallax)) : 12/9/2006 8:33:13 PM GMT
Comments
I've quoted some of your comments and added some observations in hopes of helping...
if i remove the first if (and the end if) then the engine will drive else not...
Would happen if resm <= 100. Obvious, but also consider that if resm <= 100 then f is not assigned a value. Without the outer loop, f is assigned 710 for any value of resm < 1400; 800 for any value of resm > 1500. The unhandled case of 1400 <= resm <= 1500 also leaves f unassigned.
it uses the code like it should (i checked with a debug) but it doesnt drive...
PBASIC is very robust, you may count on the fact that is doing what you programmed it to do--even if it isn't what you expect it to do.
is it possible that an if in an if does strange things?
Define strange: Unexpected? Yes. Wrong? No
i attached the full (still unfinished) code for the robot
I hope someone takes a look at this for you, I tried, but just don't have the IQ to follow every variable through the code.
resm was larger than 1500 when i tested
I think you must be mistaken. Your syntax is right, the loop is not complicated-- if resm was > 1500 going in, f = 800 coming out; however, if resm EQUALS 1500 going in f = 0 coming out.
Also, maybe someone can give input on this, I seem to remember a post that stated you couldn't use WAIT with a timeout in a SERIN command, not sure though.
Jeff T.
Just a thought have you ran a small test program on your ESC setup to make sure it is running as expected maybe set the speed with Debug in statements? Looks like you are running 2 servos and a ESC which might cause eratic operation from a BS2. Try just a ESC setup and the LCD maybe and take out the servos...
lets us know
and now it DOES work like i expected. i still don't know what was wrong with my old code but i'm glad i got it working.
thanks for all your input.
this code part of my Local Positioning system robot that I'm building for school. and the resm variable is the distance to a reciver in mm. so with this code it should stay between 1,4m and 1,5m from the receiver.