Shop OBEX P1 Docs P2 Docs Learn Events
electronic speed controller — Parallax Forums

electronic speed controller

ChrirozChriroz Posts: 8
edited 2006-12-10 13:06 in BASIC Stamp
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 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

  • LSBLSB Posts: 175
    edited 2006-12-09 19:47
    Chriroz,
    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.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2006-12-09 23:47
    Hi Chriroz, as LSB said your syntax is right, if you remove the first if/endif and it drives I would say that Resm is less than 100 which would be seen as true when it arrived at··"ELSEIF·resm·<·1400·THEN" which would make f = 710. So maybe you could try and verify the value of Resm with a DEBUG placed just before the first if statement because I think its not delivering what you are expecting.

    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.
  • bennettdanbennettdan Posts: 614
    edited 2006-12-10 01:48
    Hi Chriroz

    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
  • ChrirozChriroz Posts: 8
    edited 2006-12-10 13:06
    i changed the code into:

    IF resm > 1500 THEN
        f = 785
        PULSOUT 13, f
    ELSEIF (resm < 1400) AND (resm > 100)THEN
        f = 710
        PULSOUT 13, f
    ELSE
        f = 750
        PULSOUT 13, f
    
    ENDIF
    
    


    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.
Sign In or Register to comment.