United Kingdom
Asked — Edited
Resolved Resolved by Dave Schulpius!

Motor Controller Ramping Script Help

E4-B4 has been a little neglected lately, so or been playing trying to give him more graceful drive movements, so I'm looking for a little help with a ramping script to be used in a custom Movement Panel for my motor controller. I read a thread some time ago where DJ posted that ServoSpeed() commands can be used, so I have tried the following script for moving forwards...

servospeed(d3,5)
servospeed(d1,5)

PWM(D3, 0)
PWM(D1, 0)

Set(D2, Off)
Set(D0, Off)

PWM(D3, 65)
PWM(D1, 65)

I have setting tried different servo speeds, but the ramping part does not seem to work. I have also had a go at converting @Rich's Sabertooth ramping script, but could not get my head around where I needed to make the changes. Can anyone help me with a ramping script to ramp up when I hit forward or reverse, and ramp down when I hit "Stop" for the following movement commands...

#Forwards
Set(D2, Off)
Set(D0, Off)
PWM(D3, 65)
PWM(D1, 65)

#Reverse
Set(D2, On)
Set(D0, On)
PWM(D3, 65)
PWM(D1, 65)

#Stop
Set(D2, Off)
Set(D0, Off)
PWM(D3, 0)
PWM(D1, 0)

Thanks.


ARC Pro

Upgrade to ARC Pro

Synthiam ARC Pro is a new tool that will help unleash your creativity with programming robots in just seconds!

#1  

I may be way off base here, but if I were trying to get a servo to ramp up I would try:


$TopSpeed =65 #Whatever top speed number would be
$NextInc =1
repeatwhile $NextInc <= $TopSpeed
  servospeed(D0,$NextInc)
  servospeed(D2,$NextInc)
  sleep(500) #Just a guess. Whatever rate of ramping you want.
  $NextInc++
endrepeatwhile

If the ramping is too slow incrementing by 1 you could increment $NextInc by a larger number. Though probably changing sleep time would do the trick.

I haven't actually tested this. Just off the top of my head.

Same for ramp down but start at current speed setting and decrement until minimum/stop speed setting is reached.

United Kingdom
#2  

@WBS.

Thanks for the reply. I'm not sure if that's the kind of thing I'm looking for, but it could be. Not sure how to use it with my direction commands, but I'll have a play with it to see if I can make something of it (unless someone comes up with another solution).

Thanks, and happy holidays.:)

United Kingdom
#3  

Bumping thread as I still need help with this.

#4  

Steve, are you using a Sabertooth?

#6  

The servospeed only adjusts ramping on continuous rotation servos. Something like the Sabertooth ramping script is needed for a PWM H-bridge (although interestingly, if you drive your movement with a joystick/game controller it ramps the PWM so maybe this is something DJ could just add to the Movement Panel to do when driven by the keyboard or script commands too)

If you are using a Sabertooth, I am pretty sure you can turn on Ramping with Describe software. Now that I finally have my basement back and getting my tools unpacked, I am finally going to wire up my Sabertooth to some wheelchair motors and start getting some hands-on knowledge on this.

Alan

United Kingdom
#7  

Hey Alan.

This is a quote from DJ talking about the script example he posted in the link on post #1 above...

Quote:

For PWM H-Bridge, simply use the ServoSpeed(). As in my above example. The servospeed() will ramp the speed between PWM's.
It looked to me that this should work with the motor controller I'm using as it uses PWM as well. It will be a couple of months at least before I get my hands on a sabertooth, so I'm stuck using the motor controller in post #6 for now.

#8  

Hmm... I'll play with that on my Roli which has an LM298 H-Bridge and see if I can figure it out. As usual, no guarantee on time. Lot's to do and not enough hours in a day to do it...

Alan

United Kingdom
#9  

Lol, Alan, I know exactly what you mean.

Anyway, thanks.

#10  

I got a pretty good ramping effect by sending multiple increasing PWM values to my h-bridge when I was using them before I switched to Sabertooth. Just put a short sleep() between each one. It's easy to ramp up like that. The hard part is ramping back down. Even if you are able to get feedback of some kind it's hard to get a good rampdown to zero speed.

United Kingdom
#11  

Thanks Dave. I did play about with that idea with a Roomba a while back, although it didn't work very well. I'll try it with the motor controller and see what happens.:)

United Kingdom
#12  

I ended up using Dave's idea of using sleeps In between different PWM values. It's not pretty with the ramping down to stop part, but it's better than it was. If anyone has any better suggestions, I'd love to know what they are.

Anyway, thanks guys, and Dave especially for giving me a nudge in the right direction.:)

@Alan.

Did you get to play around with the L298 ramping idea with Roli?

#13  

Quote:

@Alan.

Did you get to play around with the L298 ramping idea with Roli?

Not yet.

Alan

United Kingdom
#14  

Okay Alan. No worries.

United Kingdom
#15  

I've not had much time to myself recently, but managed to find a couple of hours today to play robots, and set about sorting out E4-B4's movement ramping. I have a Sabertooth 2x25 on order now to replace the current motor controller, but in the meantime while I,m still using this controller, I'd like a little help with a "ramp down" script. Currently on my mobile interface, I have an if($pressed) variable so when the forwards button is pressed, the robot moves forwards. Press the same button again, the robot will stop using the following script that Dave S suggested...

if (!$pressed)
Set(D2, Off)
Set(D0, Off)
PWM(D3, 38)
PWM(D1, 30)
sleep(100)
Set(D2, Off)
Set(D0, Off)
PWM(D3, 48)
PWM(D1, 40)
sleep(100)
Set(D2, Off)
Set(D0, Off)
PWM(D3, 58)
PWM(D1, 50)
sleep(100)
Set(D2, Off)
Set(D0, Off)
PWM(D3, 68)
PWM(D1, 60)
$pressed = 1

ELSE
Set(D2, Off)
Set(D0, Off)
PWM(D3, 40)
PWM(D1, 40)
sleep(150)
Set(D2, Off)
Set(D0, Off)
PWM(D3, 30)
PWM(D1, 30)
sleep(150)
Set(D2, Off)
Set(D0, Off)
PWM(D3, 20)
PWM(D1, 20)
sleep(150)
Set(D2, Off)
Set(D0, Off)
PWM(D3, 10)
PWM(D1, 10)
sleep(150)
Set(D2, Off)
Set(D0, Off)
PWM(D3, 0)
PWM(D1, 0)
$pressed = 0

endif

and have similar scripts for reverse, turning differential left/right and U turn left/right. This works great, and gives a good effect, both ramping up and ramping down. But here is where I need the help. I also use the iPhone sensor stream control for drive movement as well, and use the movement commands such as Forwards() etc in a custom movement panel. So an example of the movement control panel scripts are as follows...

#Forward GO ramp up.
Set(D2, Off)
Set(D0, Off)
PWM(D3, 38)
PWM(D1, 30)
sleep(100)
Set(D2, Off)
Set(D0, Off)
PWM(D3, 48)
PWM(D1, 40)
sleep(100)
Set(D2, Off)
Set(D0, Off)
PWM(D3, 58)
PWM(D1, 50)
sleep(100)
Set(D2, Off)
Set(D0, Off)
PWM(D3, 68)
PWM(D1, 60)

and the "STOP" button to ramp down to "Stop"...

#Forward STOP ramp down
Set(D2, Off)
Set(D0, Off)
PWM(D3, 40)
PWM(D1, 40)
sleep(150)
Set(D2, Off)
Set(D0, Off)
PWM(D3, 30)
PWM(D1, 30)
sleep(150)
Set(D2, Off)
Set(D0, Off)
PWM(D3, 20)
PWM(D1, 20)
sleep(150)
Set(D2, Off)
Set(D0, Off)
PWM(D3, 10)
PWM(D1, 10)
sleep(150)
Set(D2, Off)
Set(D0, Off)
PWM(D3, 0)
PWM(D1, 0)

This is all good. But the issue arises when I use a reverse or turning ramping script. For example, reverse ramping "up" is no problem... but when I press "STOP" to ramp "down" to stop the motors, it will obviously still use the "ramp down" from forwards script which causes problems, and excess strain on the gearboxes instantly changing direction at speed. So I need a "STOP" script to do a if moving forwards, ramp down from forwards. If moving in reverse, ramp down from reverse. Same for turn left and turn right.. I've had a play using "IF" and "ELSEIF" commands in various testing scripts, but have not had much success getting it to do what I need it to.

Like I said, I have a ST2x25 coming soon, but I still have a couple of robots that use the motor controllers this thread is talking about, so having a solution for this would be very useful... and maybe for others too.

Any help anyone can offer with with this custom Movement Panel ramping "STOP" script, would be appreciated.:)

#16  

Just throwing out an idea without trying it, but what if you have each directional script set a variable when it starts and have the stop look for the value of that variable and take the appropriate steps to ramp down from that direction, and also setting the variable back to "stopped"?

Alan

United Kingdom
#17  

Thanks Alan.

I did think of setting the direction commands as variables might be the way to go, and after my other try's at composing a working script, I did start to write one using this idea but I gotta be honest, I hit a wall pretty early on as I'm not sure how to fully write the script. I don't normally ask for script examples as I like to try to work it out for myself, but in this case I'd be grateful if someone could post a "stop from forwards" and "stop from reverse" example as I'm at a loss of how to write it. I can work out the turning scripts from there.

Thanks.

#18  

At the end of each direction script, set a variable to the current direction like:


$direction = "reverse"

The your stop script, insert your ramp down code in the appropriate sections of this script:


if ($direction = "forward")
#do stop from forward tasks
endif
if ($direction = "reverse")
#do stop from reverse tasks
endif
if ($direction = "right")
#do stop from right tasks
endif
if ($direction = "left")
#do stop from left tasks
endif 
$direction = "stopped"

Alan

#19  

I was never able to successfully get a script to ramp down. The hardest part was figuring out when to start the ramp and how fast to ramp down so you reach zero speed at the very end of movement. I was kinda close once when I used some math in the script to figure out the length of the move and start the ramp down script about 20% before I reached the end. Then I started the declining PWM commands. It was mostly timing and luck. I think I got the idea and tips from toymaker. Sorry I don't have though scripts anymore. I ditched them when I switched over to Sabertooth and Kangaroo's.

United Kingdom
#20  

Great stuff. Thanks for that Alan. When I started writing the script using the variables, I was going to use "elseif's", so I had that wrong straight off, lol (over thinking things as usual). This makes much more sense, and simpler than I thought. Thanks again.

@Dave.

Yeah, when I tried this on my Roomba a while back, I never really got a great effect for ramping down either. But in this situation it actually works quite well. I played around with the sleep() values to see what worked best, and 150 seemed to be the magic number for both ramping up and down for this particular setup. I'll do a quick video demo of the ramping in action and post it on my E4-B4 showcase.

The motor controller this thread is about has an automatic braking function which stops the motors dead, and I was always worried that E4 might tip over from or to maximum speed. This is a great help.

Thanks again guys.

Steve.:)

#21  

You could probably get fancy with the left and right scripts too so that you don't need to stop first and it continues at previous speed instead of suddenly dropping speed before ramping back up into the turn, but that is more than I can wrap my head around thia morning.

Alan

United Kingdom
#22  

Cheers Alan, that is a good thought and something for me to play about with. I've also got to incorporate two ping sensors in to this as well for object avoidance, so I'll have a go at adding it all together over the next few days.

Thanks again.