Community Question

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...

Code:

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...

Code:

#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.

thetechguru
Commented January 2016
At the end of each direction script, set a variable to the current direction like:

Code:


$direction = "reverse"



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

Code:


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

Dave Schulpius
Commented January 2016
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.
Steve G
Commented January 2016
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. :)
thetechguru
Commented January 2016
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
Steve G
Commented January 2016
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.
Question
AvatarSteve G
Asked on Thursday, December 24, 2015