Go Down

Topic: Dimension Engineering Kangaroo x2 & Sabertooth - Looking for Skid Steer Example (Read 430 times) previous topic - next topic

fawnlake1

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

Code: [Select]
/*
   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?

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

fawnlake1

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

A post from 2014 https://forum.arduino.cc/index.php?topic=273003.msg1936734#msg1936734

A detailed read of https://www.dimensionengineering.com/software/KangarooArduinoLibrary/html/ has me more confused than when I started..

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

Code: [Select]

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

fawnlake1


Go Up