Shop OBEX P1 Docs P2 Docs Learn Events
S2 Ramp Code — Parallax Forums

S2 Ramp Code

william chanwilliam chan Posts: 1,326
edited 2011-03-25 08:49 in Robotics
I wrote my own ramp up and down code like this
PRI ramp_forward(Dist)

    if Dist < 1000         ' minimum dist
         s2.set_speed(7)
         s2.go_forward(Dist)
         return

    s2.set_speed(5)           ' Ramp Up 500   
    s2.go_forward(100)
    s2.set_speed(10)
    s2.go_forward(400)

    s2.set_speed(15)         ' Full speed ahead
    s2.go_Forward(Dist-1000)
         
    s2.set_speed(10)         ' Ramp Down 500    
    s2.go_forward(400)
    s2.set_speed(5)
    s2.go_forward(100) 

but the S2's movement stop momentarily at each speed change. This makes the movement jerky.
How do I ramp smoothly?

Comments

  • Martin_HMartin_H Posts: 4,051
    edited 2011-03-25 08:49
    I read through the S2 object as a learning exercise and it looks like the motor driver does ramping. The speed you set is the max speed on the path. But the S2 object has the concept of a current speed as well as an end speed. For a go forward a certain amount the end speed is zero, so you don't chain them together to ramp.

    But I am thinking that since the S2 object works at such a higher level of abstraction you don't need to ramp by hand.
Sign In or Register to comment.