
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.
Tomorrow I'm going to do a factory reset on the Kangaroo and if that doesn't get things working again I'm moving on.
To tell the truth if I have to learn all that language and write all these scripts to get a gradual ramp up and down I'm really not gaining much using the Kangaroo X2. I need speed ramping in position mode to get my B9 joint movements to look natural. I can see where this Sabertooth / Kangaroo would be a great little combo for other people in other types of platforms. It does a great job converting RC Signals and magically controlling a DC motor and accepting servo commands. If you really don't mind your motor starting up and stopping fast then the coolness of sending servo commands to a DC motor is for you.
With that said I still have this Sabertooth / Kangaroo X2 combo installed and I did a lot of rewiring to get it installed and working with B9's waist and hip motors. I'm not one to give up and hoped to get this setup to work the way I want in my B9 robot and EZB. So.... I started to rethink Glen's (irobot58) suggestion of sending gradual increasing speeds through a EZB serial port to the Kangaroo. Thanks Glen! . After some trials and more then a few errors I got it to work! I've got a first draft of a nice speed ramp up and down. The trick that works is to send a very low speed setting like s050 with a very short Sleep delay like 0050 before I go to the next gradual speed increase of s100. I continue this (keeping the Sleep to a very short 0050) up to about s300 or s400 then jump to the speed I want. In my case the best natural speed in about s500 or s600. The trick is the timing at full speed so it starts to reverse the ramp code at the right time so it drops speed back down to s050 at the very end of rotation. The result is a nice start up and a very slow cost to a stop. So the code looks something like this:
Code:
Like I said this is a ruff script that ramps nicely. I still need to work on it to see if I really need all the speed commands and if I can cut the Sleep commands even shorter. I also would like to see If I can send this script using only one SendSerial command with the speed changes called as a script.
If there are any suggestions on refining or tuning this I would really appreciate it.
Perhaps a script that incorporates a variable that adds by certain increments and subtracts will fulfil the "elegant" quality!
I have been helped so many times by the awesome people of this Forum its a pure pleasure and joy to assist someone in whatever way possible ....... Thanks for the accolade Dave
Writing scripts is not one of my strong points. I'm going to have to think about this and try a few things out. Variables may work if I can figure out how to implement them.
Increase a variable by a set amount
Code:
So to ramp up from 0 to 300;
Code:
So if you put the send serial command below the :loop label and above the IF it'll run the command, starting at 0 speed, increase by 50, loop back up, send the serial data again, increase by 50 and so on until it hits 300, when it hits 300 (after sending the speed 300) the IF will terminate the script with the halt command.
To add in the speed variable to the serial data, i.e. SendSerial(D0, 9600, "1,p2450 s300", 0x0d) you simply need to break the data at the s and add in the variable so it would be like SendSerial(D0, 9600, "1,p2450 s"+$X2_Speed, 0x0d)
The same could be done for position, but break it at the p like SendSerial(D0, 9600, "1,p"+$X2_Position+" s300", 0x0d)
Note: I haven't tested this, I am unable to as I don't have a sabertooth or a Kangaroo (yet)
Unfortunately I'm out of time, it's late and I need sleep, but hopefully that will have explained a few things and helped guide you in the right direction. If not feel free to ask about whatever you are stuck with and I'll try to explain better.
I only have a few free hours over the next few days so it may be a while till I get this working. Please keep an eye on me over the next week as I may need a helping hand on this code if your still willing and available.
@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?
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
Code:
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.
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.
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!
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:
Code:
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) :
Code:
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:
Code:
As always I'm open to suggestions or criticism. Any help is welcomed.
Thanks Dave
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:
Code:
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.
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
en.wikipedia.org/wiki/PID_controller
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
www.solutions-cubed.com/content/Downloads/MotionMind3Docs/MOTM3DS_6.pdf
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.
Tony
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.
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;
Code:
Or if the ServoUp and ServoDown commands work with it;
Code:
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
Dave, when the V4 is available, I will write this algorithm into an EZ-B script for you, if that will help.
Tony
@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 seem to be having that issues as well. How did you resolve it? How did you get the Sabertooth/Kangaroo to power down completely, and how did you make sure the Sabertooth/Kangaroo powered up AFTER the EZB was powered up?
I solved that issue by placing a relay between the battery and the sabretooth that was controlled by the EZB and ARC. When the robot was powered up the relay would be in the NO position keeping the dump battery disconnected from the Sabertooth. ARC would then run a script that would close the relay and connect the two. When The robot was powered down the Relay would naturally open and disconnect the dump battery and let the Sabertooth/Roo power down.
A much better solution is to simply buy a Sabertooth 2x32 Sabertooth. the Sabertooth 2x32 can is shipped and configured to allow it's power outputs as a voltage clamp to operate from a power supply without a parallel battery. A much more elegant solution.
So what is happening is, after I got the kangaroo "trained" with the limits (used teach mode), I created EZ-B scripts to set the max/min for both motors, set the initial speed, and set the initial position (which is the end/home position). Then I created a script to shutdown the robot, moving motors to the start/home position. Then I powered off the EZ-B and sabortooth. Then I turned them back on, ran the startup script, did some moving of the arms, and then called the shutdown script. Then power off. And repeated. This all worked fine. Then I powered off once more, left it off of several minutes, then powered back on, ran the startup script. Then when I attempted to move the arms, nothing happened, and the LED on the Kangaroo now flashed 3 times.
Don't understand why it worked a couple of times, and then quit working. When I re-power up, and run the startup script, all seems fine, no flashing LED, no errors from the script. But as soon as I try moving an arm, the LED starts flashing 3 times.
If you are using an encoder? You probably know this but you need to home the motor each time you restart.
If you are sitting on a limit switch on start up you will have issues.
How are you sending your commands? Simple Serial through the Uart or servo commands? Some of my motors I have controlled by the Kangaroo I have attached to EZB's digital ports and control using servo commands. I have had issues with them nor responding if they are out of position on startup. However I don't get an error code so this is probably not your issue.
Turns out, there is a setting called Origin which can be set via the Describe software. That Origin is the line count of the encoder, and is set to 0 when you do the Teach Mode (line count goes from negative to positive, with zero being center of travel). Using the Describe software to set the Origin to the min or max line count (shown on the position tab of Describe), will make the Kangaroo assume the start position at power up is that min or max value of the Origin.
In my case, the min line count was -1375, max was 1375. I set the Origin to be 1375, and updated Kangaroo with the new settings. Then I did a power off/on, and now everything works like I need it. I make sure my motor is at the start position (1375) on power up, and the PWM setting on EZ-robot is 1, and then there is no initial homing of the motor. Of course, I must make sure when powering down, the EZ-robot moves the motors back to the initial start positions, before I turn the power off, but that is something that has to be done anyway. Only issue will be if the power is ever cut off before returning to start positions, then everything gets out of sync. But that’s another problem, for another day.