Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
Asked — Edited
Resolved Resolved by irobot58!

Lumpy, Lets Compare Notes On Kangaroo X2 Please

Hey Lumpy (or anyone who can advise). I'm addressing this first to Lumpy because I know he is using and working with the Kangaroo X2 / Sabertooth setup. If anyone has some insight please chime in.

Anyway, as mentioned in other posts I'm working through issues with my Kangaroo X2 / Sabertooth setup where I'm using two DC motors that have pots for feedback and limit switches. I now have both motors responding through serial commands from EZ Builder. I had an issue where I was continually getting error codes at power up and would have to power cycle the unit to get it to respond to serial commands. However I found I had to make sure the Sabertooth/Kangaroo powered down completely when the robot and EZB was switched off and then powered up after the EZB was powered up.

My issue now is trying to get the speed ramping feature of the Kangaroo to work. There are different ways to set up the Kangaroo; Velocity or Position control. I cant get the speed ramping to work when serial commands are sent from EZB in either control setting. However, I can get ramping to work nicely in Velocity but not Position tests when using the "Live Test" section of the Describe software used to set up the Kangaroo. When doing these test I'm attached directly to the Kangaroo with a Serial Adapter from a USB port of my laptop and EZB is not connected.

Without any ramping my motor will jerk to full speed and stop suddenly. I've e been working with Dimension Engineering on this for weeks but it's been painfully slow. The only way I can get help from them is through e-mail and it sometimes takes days for them to respond. Then I'll get a one sentence question or answer like "sounds like you need to make sure to upload your settings and reboot" or please send us a copy of your settings. This must be a newer product with limited users. I've found no community forums and few people posting info on this board.

One other thing. What is the best way to set servo control to work independently on the Sabertooth/Kangaroo's second motor channel? So far the only way I've been able to get it to work is if I start the first motor Chanel with a servo command and don't release it. I am using a second cable attached to a second digital port on EZB and attached to S2 of the kangaroo. I'll call that port when I want motor 2 to respond to a servo command.

I must say it is a great little board and from what I've been able to set up, it works great. I like the idea of being able to send servo commands to control my DC motors. Very precise and quick. If I can get this speed ramping issue figured out it will be an excellent addition to my B9 robot motor control.

United Kingdom
Dude, I keep an eye on everyone even if I don't always post:) Glad it helped.

@irobot58 I have enough praise, I can let a few slide;)

I haven't had a chance to try this code but I've been looking at it a little. I do have a question or two;

Would I have to set this speed variable in the INT script when ARC starts up? I guess I would not have to keep the loop script running all the time waiting if I set it at start up and just call the script when I want to move the jount.

Also I have a feeling I'm going to have to change your commands from EZ Language to C++ or even VB. I'm not sure the Kanagroo will understand the EZ commands. If so I'm going to have to try to learn some of this code. I know the Kangraroo will understand code you would send from an Arduino. Any thoughts on this?
United Kingdom
If it understands the Arduino it should understand the ARC commands too. I'll have to look and see if there's any kind of serial monitor I can use to look at exactly what the Kangaroo received from both the Arduino and EZ-B though. Initially though I don't think it would be a problem.

The $X2_Speed would need to be set to something prior to running the script. If you are ramping up, at the very start of the script simply set it to 0 $X2_Speed = 0. If ramping down set it to the fastest speed at the start.

The label for the loop would come after that.

Then the If to slowly increase the speed until a set speed

The the goto

Something like


# Set the speed to 0
$X2_Speed = 0

# Make a point to loop back to

# Send the serial command
SendSerial() # Im too lazy to fill in the serial command, copy from the last page.

# Check the speed and act accordingly
IF($X2_Speed < 300)
$X2_Speed = $X2_Speed + 50

# If the speed is already at 300 end the script.

# Go back to the loop

The code will only loop until max speed (300 in the example) is reached. Once it hits 300 the IF is not true so it runs the code after the Else, which is Halt() which will terminate that script.
Cool, thanks for the fast and thoughtful reply. This all makes sense. I can't wait to have some time this weekend and give this a try.

As far as a monitor, kangaroo does feedback codes and other info like speed and position to a microcontroller. It can be seen with a terminal program on the laptop. I have tried to hook one up to the kangaroo but although I can open a channel I can't understand how to run the several programs I've tried. This is just one more thing I need to tackle. Any suggestions on a good and easy terminal program I can try and that has good instructions?

As far as info feedback from Kangaroo on position and speed maybe the new V4 will be able to read this and let me control better with" Get" statements in scripts.
Holy cats Rich ! Your code works! I'm not surprised but completely amazed that it works so well. I've been struggling with this setup for a while now and had true fears I couldn't make it move to my expectations. I've overcome many challenges and ramping was about the last issue. If I couldn't get it to work I was going to give up. Your code makes the movement ramp up very smoothly and I'm able to easily adjust the acceleration.

Now that I've got the ramp up working I'll need to get the ramp down as the rotation nears the end of rotation. I'll be working on that on the next few days. I would think the code needs to be duplicated and placed between the end of your code (with maybe a delay) and the Halt() command. I've run out of time and energy today so I'll be working on this again in a day or so when I find more of each.

Anyway, Thanks very much Rich. I'm completely thrilled!
I've now got a working script. Thanks again to @Rich for pointing me in the right direction. This successfully ramps the Sabertooth / Kangaroo X2 up to any speed wanted, move to a exact point on a radius and then ramps down to a crawl near the stop point. With the proper timing of the Sleep() command the motor ramps down just before the end and adjusts into center.

It works pretty good but the timing with the Sleep($Sleep) variable and the sleep() pauses in the call script is vital or the ramping will miss and the motor will jerk to a stop at any speed. There has got to be a way to get the position read from Kangaroo into the script. Once I figure that out I can just use Kangaroo's GetP command to start ramping at an exact point instead of relying on timing. That's my next trick. In the mean time the sleep() is working OK and the ramping script is the key part anyway. I'm still looking for other ways to ramp but haven't really tried other commands in C++ that may work. In Kangaroo's Serial Packet reference manual I did find the following but I have no idea how to work it into the script or if it will work. It may only work with the Velocity command but I dont know yet:


public KangarooMonitor S(
int velocity,
int rampLimit = -1,
KangarooMoveFlags flags = KangarooMoveFlags.Default

Any ideas? I wish I knew better how to write scripts in C++ but in the mean time:

This is the main movement script (pardon my mess) :


#The following are the variables that can be set in a call script or from within this script.

# Sets top speed. This can be called from another script.
#$Set_Max_Speed =0300

# sets the positon to stop at. This can be called from another script.
#$Positon = 2550

#sets the sleep pause be set from the call script. This lets the motor turn to the proper spot to ramp speed down. This can be called from another script. Recommended. Easier to get timing right with multiple calls.

# sets the speed to 0 to start ramping up to speed. This should always be set from within this script.
$X2_Low_Speed =0000

# Sets final speed. This should always beset from within this script
$Set_Final_Speed =0010


# Point to loop back to
# Send the serial command with wanted Kangaroo variables
SendSerial(1.D0, 9600, "1,p"+$Positon, "s"+$X2_Low_Speed, 0x0d)

# Starts at zero, Checks the speed and adds 00XX speed each time it loops till it gets to the top speed (play with it to find the smoothest ramp). Then it will to the the :Ramp Down section.
IF ($X2_Low_Speed < $Set_Max_Speed)
$X2_Low_Speed = $X2_Low_Speed + 0010
# Go back to the loop

# When the speed is at $Set_Max_Speed, sleep then ramp down.
Goto(Ramp Down)

:Ramp Down
SendSerial(1.D0, 9600, "1,p"+$Positon, "s"+$X2_Low_Speed, 0x0d) #this command may not be needed. It worked with and without it.

#sets the sleep pause variable that's set from the call script. This lets the motor turn to the proper spot to ramp speed down.

# 2nd Point to loop back to. This must be named different from the first loop!
# Sends the serial command with wanted Kangaroo variables. the $X2_Low_Speed variable is still set to the max speed by the first loop. This loop will take it down.
SendSerial(1.D0, 9600, "1,p"+$Positon, "s"+$X2_Low_Speed, 0x0d)
IF ($X2_Low_Speed > $Set_Final_Speed)
$X2_Low_Speed = $X2_Low_Speed - 0010 #this number should be set to the same as the $Set_Final_Speed varible or the motor wont crawl into exact position after ramping completes.

# When the speed is at $X2_Low_Speed, end the script.

#takes us back to Loop2 if needed.

Here's an example of the call script. I can make several scripts with different variables set depending on where I what to the motor to stop or how fast to go. It's important to adjust the Sleep() commands so the ramping happens at the right times or the ramping will happen too soon or too late. I only need one "Waist Movement" script that will keep being called:


# Sets Final speed
$Set_Max_Speed = 300

#sets the positon to stop at Left
$Positon = 3500

$Sleep = 2800

#calls the ARC EZ Script
ControlCommand("Waist Movment", ScriptStart)


#sets the positon to stop at Center
$Positon = 2550

$Sleep = 2600
#calls the ARC EZ Script
ControlCommand("Waist Movment", ScriptStart)


#sets the positon to stop at Right
$Positon = 1600

$Sleep = 2900

ControlCommand("Waist Movment", ScriptStart)


#sets the positon to stop at Center
$Positon = 2550

$Sleep = 2700

#calls the ARC EZ Script
ControlCommand("Waist Movment", ScriptStart)


#Shuts down the Sabertooth. The above sleep() keeps it from shutting down too soon and stopping the motor
ControlCommand("Start", ScriptStart)

As always I'm open to suggestions or criticism. Any help is welcomed.

Thanks Dave
I like these scripts. Couldn't they be incorporated into the movement panel? For instance a check box for ramp up and ramp down then if they are ticked, a box for the rate is enabled. A handy feature to be sure. I asked a similar question at one time on the servo control.
Humm, that's a cool idea. Maybe some day when the team get more time they could look into this. IMHO ramping is an area that really needs to be addressed not only with EZ Robots but with other companies that provide motion control boards. It seems like it's just an after thought or partially implemented. I may be wrong about all this but I haven't found much where this is a concern. With people now building larger and more human like robots I imaging the need to get them to move more naturally is going to be in demand. They all really should address this lack of support to stay ahead. The kangaroo does do adjustable ramping but only in Velocity Mode unless you do involved scripting that most people (like me) don't know how to do. Velocity Mode is good for RC controlled bots and cars that just drive forward, reverse and turn. I need position and speed control. DE says their Kangaroo doesn't do ramping in Position Mode unless you script. WHY?

The only way I was able to get ramping to work on my DC Motors with ARC was to send gradual increased or decreased PWM commands. That actually worked very nicely. That script looks like this:


$adcSpecified = 185
controlcommand("Move Waist", scriptstart)

To be honest I got smoother ramping with simpler EZ code (as seen above) then I am getting with the Kangaroo script I just made over serial. I'm still not really convinced my new setup using the Sabertooth/Kangaroo is better then what I had with a H-bridge and a pot attached to an ADC port on the EZB. The Sabertooth is more rugged and top quality and the Kangaroo does do all the work that EZB used to do. Added to that, I now only use one Digital port on the EZB and send all info with a serial command. Also, I can now use servo commands but I found if I mix servo commands and serial commands using the same Digital port on EZB everything will lock up and I need to reboot everything. So it's one or the other. With servo commands I have no ramping. It's all or nothing.
United Kingdom
Dave, I do not use Sabertooth or Kangaroo controllers, so have little knowledge of them, but here are some thoughts.

I guess that your main problem is not getting the position feedback so the script does not know when to start ramping down as it approaches the target position. The lack of serial comms (read) on the V3 is a real problem sometimes, but it should be solved when the V4 arrives, as it has bi-directional comms. You really need a thing called analogue PID (proportional-integral-derivative) controller see


With a controller like this using PID the motor would move very smoothly from start position to (accurately) the target position thanks to the on board PID algorithm. I use the Motor Mind 3 controllers with great success on the EZ:1 robot using serial PID control, the robot accurately moves from one location to another. Serial mode uses encoders but the mode you need is analogue (using positional feedback resistor). Here is a link to the Motor Mind 3


One thing to note, I found that PID is quite complicated and very difficult to set up properly, it may be worth waiting for the V4 as PID may be a steep learning curve for you. Once you get the V4 with bi-directional comms you could roll out a simple script like

1) Extract start position value from end position value = travel_v - [example if start_pos = 500 : end_pos = 2600 then travel_v = 2100]
2) If travel_v < (min position to ramp) then goto move - what this means is that if the travel_value is to small its does not need up/down ramping
3) Calculate (say 10%) of travel_v - [2100/100*10 = 210]
4) Add this value to start_pos = pos_2 - [500+210 = 710]
5) Slow ramp-up motor until current_pos = pos_2 [710] - slow ramp_up speed from start position to position 2 (end of ramp-up)
6} Calculate pos_3 (say 90%) of travel_v - [2100/100*90 = 1890]
7) Motor full speed until current_pos = pos_3 - set motor at full speed until reaching 10% before end position
8) Slow ramp-down motor until current_pos = end_pos - slow ramp_down for position 1890 to position 2100 (end position)
9) Target position attained

In the above example the first 10% of travel is slow ramp-up with the next 80% of travel being full speed and the last 10% being slow ramp-down. The ramp up/down percentage (10% in the example) may need to be changed to suit the particular motor setup that you have.

I hope I have interpreted your problem correctly and this has been of some help.


Thanks so much for sharing your thoughts here. You've confirmed what I thought the problem may be. I really have been hampered by not having two way serial communication between EZB and the Kangaroo. That and the lack of good documents or active Kangaroo community forums and my lack of C++ script writing knowledge has made this a true struggle with slow progress.

Also thanks for the tip and link to the PID board. I don't think I'm up for another steep learning curve just yet so I think I'll wait for my Pre-ordered V4 EZB. Hopefully it will be here in a matter of weeks. That sounds like the natural solution. Your outline of a script will help a lot when I get back to this point.

I the mean time I'll keep plugging away. Heck, even a blind squirrel finds an acorn once in a while. :)
United Kingdom
I haven't had chance to check this topic for a while (and even now I've just quickly skimmed over it), glad the script got you going:)

On the servo commands and no ramping, you could use scripts to simulate ramping by moving the position step by step with sleep between... Something like;


Servo(D1, 10)
Servo(D1, 11)
Servo(D1, 12)
# and so on
Servo(D1, 20)
# and so on

Or if the ServoUp and ServoDown commands work with it;


$new_position = 90
$steps = 1

If(GetServo(D1) < $new_position)
ServoUp(D1, $steps)

The above would need more work, using Tony's algorithm and some error checking along with some code to make sure that moving the servo up by $steps wont push it over the $new_position - something like IF(GetServo(D1) + $steps > $new_position).

It may be simpler than that, I will admit I didn't put much thought in to this one but the concept is the point I am trying to get across and hopefully I have done so:)
@Rich, Your best guess without much thought is a whole lot better then my hours of slight progress. I did get ramping to work like this on other applications with PWM commands. I didn't think about trying it on servo commands. Thanks once again!
United Kingdom
@Dave, with my algorithm I need to add the following, because of the lag time it takes for the EZ-B to read the position (back from the Kangaroo), it is likely that the actual position will "over shoot" when the equality checks (10% in the example) are being made, especially when the motor is on full speed (like when going to pos_3) etc. So the check should not be for equality, it should be ">" (more than), this will allow for any over shoot.

Dave, when the V4 is available, I will write this algorithm into an EZ-B script for you, if that will help.

Thanks Tony... that will help me as well. I just picked up a couple of kangaroo boards myself...
@Tony, Once more you've proved what a great guy you are. I couldnt get most of this stuff to work the way I want to without people like you offering help. I intend to learn this type of programing soon so I dont have to relay on good people like you so much. In the mean time I will gladly accept your offer of help. When the V4 arrives I'll contact you. Fit it in as your scheduel allows. Many thanks! :D

@Richard, When you start to install your Kanagroo please contact me if you like. I'll gladly share what I've learned so you dont have to struggle through what I have. It's a good PID board but documentation sucks and it seems to me that what they do have is geared towards the more advanced among us.
I just ordered C# for Dummies and C++ for Dummies off of Amazon. Free 2 day shipping so it should be here by the weekend. I really want to understand what I'm asking here and hopefully lend a hand. I know it's a complex language and will take some time to learn but at least this will give me a base and a start. Hopefully I'll be able to at least write a simple cammand to send over serial and know what I'm trying to do. ;)
If you buckle down C shouldn't be too difficult... I use EasyC for my vex stuff, but it's not C... it does spit out C pseudo code so one can see how C works as a language... However, EasyC is really just a graphical language that has almost no C programming for the user. Robot C is another Vex controller (among others) language that is nearly full blown C... That I wouldn't mind learning... I do agree with you C is worth learning.. I would learn C for no other reason than to establish a serial connection between my EZB and the Vex controller .... Maybe I should I should learn it, then...;)
interesting and informative thread, Dave I need hep with this
Hey Reed, good to hear from you. I'll be glad to help as much as I can but I'm at work right now and have a busy evening ahead of me. I'll try to get back to you on this as soon as I can. This is all thread and lots has changed since then. Good news is that the kangaroo now has built-in ramping. You do have to access the controls through the software which means you need cables connected in the proper way to your computer. It's all a little confusing and frustrating at first but once you get the hang of it it's really an awesome and easy to adjust set up. Getting into the software and making adjustments is the best way to get the best results. You will also need a good feedback device attached to your kangaroo and your motor. Pots are okay but I really suggest encoders. Once you have a kangaroo properly tuned and your ramp settings adjusted the ez script to move your motor is very easy. Just a few lines and some sleep commands and you're good to go. By the way I connect my kangaroo 2 my EZB through the serial port. That's the only way you can get feedback to the kangaroo from your encoder. I can send you any commands you will need to put in your script. Good luck and have fun. I'll talk to you later.