Shop OBEX P1 Docs P2 Docs Learn Events
Motor code question — Parallax Forums

Motor code question

I am new to robots and so any help is appreciated. i want to ramp a motor from slow to full and maintain that full speed untill the ping sensor determines it needs to take action. Ive tried using the index variable but cant get it to stay at full no matter what i do. heres what i have so far

FOR index = 250 TO 0
PULSOUT esc,750+index
PAUSE 20
NEXT

ive changed the pause value but it just acts up.

Comments

  • If you want to ramp from slow to full, I believe you should change to
    ...FOR index = 0 to 250
    as 750 is zero speed
  • yes i wrote that wrong but how do i keep it going at full speed
  • To keep the motor moving, you have to keep issuing control pulses about every 20ms. Fortunately, the PING has a cycle of 20ms or less and most servo motors will tolerate a cycle of a little more than 20ms. What you have to do is trigger the PING and wait for an echo or timeout, figure out from the PING time how much time is left in the 20ms cycle and PAUSE enough to reach that point, then do the PULSOUT for the servo. This doesn't leave much time to do anything else and is why most programs for robots move the robot for a short distance, stop it and do a PING and figure out what to do next before moving again. It sometimes helps to use a faster Stamp model (like a BS2px) or switch to using a Propeller.
  • What are you sending the servo after the ramp loop terminates? Servos need to be updated at least every 20 milliseconds to maintain their position or speed.
  • im not using servos, im controlling an esc to a dc motor. i just want to know how to ramp the motor from start to full speed and keep running at full speed indefinitely. ill figure out the rest but for now i need to figure this out
  • ercoerco Posts: 20,256
    edited 2016-03-04 22:51
    What's the correlation between pulse width & speed for your particular ESC? Does it use standard servo-style pulses, 1.5 ms (pulsout 750)= stop, with forward/reverse extremes at 1.0 and 2.0 ms?
  • yes it does
  • I found one way to do it but Id like another option or to know if Im doing this wrong to begin with

    FOR index =0 TO 250
    PULSOUT esc, 750+ index
    PAUSE 20
    NEXT
    DO
    PULSOUT esc, 1000
    LOOP
  • ercoerco Posts: 20,256
    edited 2016-03-04 23:02
    Assuming your initial code works, then per Mike & Hal you must keep sending full speed pulses to keep it moving, while checking your PING sensor.

    'ramp up
    FOR index = 250 TO 0
    PULSOUT esc,750+index
    PAUSE 20
    NEXT

    'now maintain full speed while checking sensor
    DO
    PULSOUT esc,750
    insert PING routine here
    IF... THEN branch based on PING reading
    IF... THEN branch based on PING reading
    LOOP
  • thanks thats what i was missing
Sign In or Register to comment.