Dimension Engineering Kangaroo x2 & Sabertooth - Looking for Skid Steer Example

Hi,

I have a robot under construction and am hitting a wall with my particular setup and am really struggling to understand the vendor (Dimension Engineering) examples and supplied library. I have exhaustively searched Google, this forum and many other resources in search for a sample of code that works.

Specifically my issue is the Kangaroo x2 serial commands.

My setup is a large dual 24v motor (skid steer) chassis with 400 pulse encoders mounted to the motor shafts.

Sabertooth 2x32 controller
Kangaroo x2 (Packet Serial Mode)
Encoders ROTARY_ENCODER_HN38-06-N.pdf
Arduino Uno
Single analog joystick

The DeScribe software from Dimension works fine and the results are as expected (motors turn and move as instructed). However for the life of me I am unable to get the kangaroo library to do anything that makes sense to me. I can make the motors move and then as I try to make changes to speed or position I get usually very bad results.. drive chatter, controller lock out etc etc.

For example the provided mixed-mode.ino makes my system stutter and shake and lock up. It makes no difference what values I place in the commands for the most part.

I am specifically looking for working examples of the DRIVE & TURN commands that I can learn and build from.

Here is some of the code I am trying and this basically works for driving Forward or Backwards and turning, but is very jittery and tends to trip the motor controller protection (stops the controller).

/*
   Test Code v1.0 for simple joystick control
*/

#include <SoftwareSerial.h>
#include <Kangaroo.h>

// Assign Pins
const int ForeAft_Pin = 2;        // Remote Control Joystick Fore/Aft - X Axis
const int LeftRight_Pin = 3;        // Remote Control Joystick Left/Right - Y Axis
const int Kangaroo_Rx_pin = 10;        // Arduino Receive Pin to Kangaroo S2
const int Kangaroo_Tx_pin = 11;        // Arduino Transmit Pin to Kangaroo S1

// Create variables to read Remote Control joystick values
float ForeAft_Input ;       // Variable to store data for Fore/Aft input from Remote Control joystick
float LeftRight_Input ;     // Variable to store data for Left/Right input from Remote Control joystick

// Misc. Variables
int Fore_Limit = 0;        // High ADC Range of Joystick ForeAft
int Aft_Limit = 1023;        // Low ADC Range of Joystick ForeAft
int Right_Limit = 1023;        // High ADC Range of Joystick LeftRight
int Left_Limit = 0;        // Low ADC Range of Joystick LeftRight
const int Deadzone = 30;        // Set the Joystick deadzone
int ForwardReverse_power = 0;        // Kangaroo -127 for full reverse, 0 for stop, +127 for full forward.
int LeftRight_power = 0;        // Kangaroo -127 for full CounterClockwise, 0 for stop, +127 for full Clockwise

SoftwareSerial SWSerial(Kangaroo_Rx_pin, Kangaroo_Tx_pin);        // RX, TX on pin 11 (to S1).
KangarooSerial K(SWSerial);        // Use SWSerial as the serial port.
KangarooChannel Drive(K, 'D');
KangarooChannel Turn(K, 'T');

void setup() {          // Put your setup code here, to run once:

  SWSerial.begin(9600);        // Establish serial connection to Kangaroo
  SWSerial.listen();
  Drive.start();
  Turn.start();
  Drive.si(0);        // Set Kangaroo to zero ForwardReverse motion
  Turn.si(0);        // Set Kangaroo to zero LeftRight motion

  Serial.begin(9600);        // Establish serial connection back to computer for debugging

}

void loop() {          // Put your main code here, to run repeatedly:

  // Read the joystick values
  ForeAft_Input = analogRead(ForeAft_Pin) ;        // Read the Fore/Aft joystick value
  LeftRight_Input = analogRead(LeftRight_Pin) ;        // Read the Left/Right joystick value

  // Convert the joystick values to Kangaroo / Sabertooth values
  ForwardReverse_power = map(ForeAft_Input, Fore_Limit, Aft_Limit, 127, -127);        // Translate and scale joystick values to Kangaroo values
  LeftRight_power = map(LeftRight_Input, Left_Limit, Right_Limit, 127, -127);        // Translate and scale joystick values to Kangaroo values

  // Need to setup the joystick deadzone

  // Command the Sabertooth to drive the motors.
  Drive.pi(ForwardReverse_power);        //Command the Kangaroo ForwardReverse motion
  Turn.pi(LeftRight_power);        //Command the Kangaroo LeftRight motion

}

Does anybody have some working code they could share? I would be VERY grateful.

Last question is concerning the Encoder Calculator page .. what do I do with the results?

Arduino Code
DriveChannel.units(718, 1800);
TurnChannel.units(360, 5200);

Decided to give some basics a try again and see what I get..

A post from 2014 Sabertooth Kangaroo packetized serial programing questions - #5 by olbap323 - Project Guidance - Arduino Forum

A detailed read of Kangaroo Library for Arduino: Welcome has me more confused than when I started..

Some test code that I am going to break apart and play with.

#include <SoftwareSerial.h>
#include <Kangaroo.h>

#define TX_PIN 11
#define RX_PIN 10

// Mixed mode channels on Kangaroo are, by default, 'D' and 'T'.
SoftwareSerial  SerialPort(RX_PIN, TX_PIN);
KangarooSerial  K(SerialPort);
KangarooChannel Drive(K, 'D');
KangarooChannel Turn(K, 'T');

void setup()
{
  Serial.begin(9600);
  SerialPort.begin(9600);
  SerialPort.listen();
  
  Drive.start();
  Turn.start();
  
  Drive.si(0);
  Turn.si(0);
}

void loop()
{
  
// Trying various commands to see what happens
// Pseudo code with all delays removed for clarity here

  Drive.pi(500).wait(); // low speed and jittery
  
  Drive.pi(1000).wait(); // better (still low) speed and smooth

  Drive.pi(5000).wait(); // no change - (still low) speed and smooth

  Drive.si(2000); // ramps and moderate speed and smooth - never stops

  Drive.s(2000); // moderate speed and smooth - never stops

  Turn.pi(500).wait();  // causes violent ratcheting and chattering

  Turn.pi(1500).wait();  // causes violent ratcheting and chattering
  
}

My struggle to understand the drive.pi drive.si drive.s drive.xxxxx and turn.. etc.

Any other examples out there?

Nobody is using a Sabertooth with a Kangaroo x2?

Hey there,

I'm not writing with answers alas, but have started working on a similar project and am wondering if you got anywhere. Last summer I built RC lawnmower with an FPV camera that uses the Sabertooth with the Kangaroo2 with optical encoders and electric wheelchair motors. I've driven the mower both with and without the Kangaroo and it definitely makes a big difference, but tuning the Kangaroo has been a nightmare.

Now I'm at the point where I'd like to add an arduino and orientation sensor to see about adding compensatory power to the left or right motor to compensate for a side-slope on our hill. I've found some good tutorials online for everything but the Kangaroo aspect.

Are you still working on this project and have you gotten anywhere? I'd be happy to correspond or share results if you are interested.

--Travis