This topic has 5 replies, 2 voices, and was last updated 7 years, 11 months ago by SuperDroid.

  • Author
    Posts
  • #3391
     beech
    Participant

    Hi,

    I have your xbee analog joystick hooked up to a sabertooth 25 and it works perfect. However, i’m now trying to simplify by eliminating the wireless xbee and run a joystick straight from 1 arduino to a sabertooth MC. I was smart enough to order another joystick and MC from you, but that is where my brilliance ends. My arduino knowledge is so limited that I can’t seem to figure out how to eliminate the xbee code and combine XBee_joystick.ino and XBee_reciever.ino to run from a single uno. Any guidance would be appreciated.

    #3392
     SuperDroid
    Keymaster

    Hi,

    To make this work, you need to:
    1. Read the joystick values by calling analogRead(axis1pin) and analogRead(axis2pin). These reads will give you values from 0-1023.

    2. Scale both of your analogRead values from 0-1023 down to the range -127 to 127. In XBee_receiver.ino, these values are scaled down to 0-255 then sent to the receiver. XBee_receiver then subtracts 127 to get the correct range. Let’s call these values drive_value and turn_value.

    3. Use the Sabertooth library’s ST_control.drive(drive_value) and ST_control.turn(turn_value) to control your motors. You can see this happening near the end of loop() in XBee_receiver.ino. It sounds like you have the Sabertooth library installed correctly, so in the Arduino IDE you should be able to go through File->Examples->Sabertooth to find some example sketches that make use of the Sabertooth library if you want. Also, make sure you call ST_control.autobaud() in setup() to initialize the Sabertooth to the correct baud rate.

    #3431
     beech
    Participant

    Thank you for your reply, very helpful.

    Back to the Xbee Joystick, can I change the sensitivity of turn? Drive is fine, but turn which is on “analogRead(A0)” is overly aggressive for my project. Again, this is my first time with arduino so maybe i’m just missing obvious settings in the joystick’s .ino file

    Thanks again,

    #3432
     SuperDroid
    Keymaster

    You could reduce turn_value by some factor before sending the speed command to the Sabertooth. For instance, this would reduce your turn rate to 2/3 range:

    turn_value = 0.67 * turn_value;
    ST_control.turn(turn_value);

    #3443
     beech
    Participant

    thank you, that seems to work but wanted to make sure i’m not interfering with your inputBuffer and reduction from 255.

      if (inputBuffer[0] == 'S' && inputBuffer[1] == 'D' && inputBuffer[2] == 'R' && inputBuffer[5]==(inputBuffer[3]+inputBuffer[4])>>1) 
      {
        drive=-(inputBuffer[3]-127); //Normalize values once the header and checksum have passed
        turn=inputBuffer[4]-127;
        
        // Drive and turn commands
            //wire connect = turn black to m2a / drive red to m1a
        ST_control.drive(drive);
        //  5/22 test @ 67%
        turn=0.15 * turn;
        ST_control.turn(turn);
      }
    #3446
     SuperDroid
    Keymaster

    This is correct since you’re scaling the turn value after the packet has been checked and normalized.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

Login Register

©2024 SDRobots.com | All rights reserved.

Log in with your credentials

or    

Forgot your details?

Create Account