User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 561
Joined: Sat Nov 02, 2013 2:06 pm

Sabertooth 2x32 Autonomous and R/C

Fri Apr 21, 2017 8:38 am

Hi;

Sorry for the ambiguous title but heres what I am trying to do.
I am building a motorised chassis using 2 x wheelchair motors and have just received a 2 x 32Amp Sabertooth Motor Driver.

What I would like to achieve is to have 2 forms of control:

1. R/C control to provide manual control of the chassis.

2. Autonomous control so that the chassis can drive itself.

Can anyone help by advising me as to what would be the best / simplest / neatest route to achieve this. Or point me to anyone that has done thisI have found out the following:

My intention was to hook up an R/C receiver to the Sabertooth for the R/C side (very simple) and use a Raspberry Pi hooked up via a serial interface however after doing some research it would appear that controlling the Sabertooth Serial using a Raspberry Pi would require additional hardware such as a level shifter due to the Pi Serial output being 3.3v and the input required by the Sabertooth being 5v. Some information I have read is ambiguous say that you may get away with 3.3v ?

Anyway I am looking for a solution to control the Sabertooth using a Raspberry Pi via serial (possibly using an Arduino as an interface but I have done this before with difficulty - it worked but with no fine control).

Regardless of the info I have found on reading the Sabertooth manual it does however suggest that the Sabertooth can be controlled using a Raspberry Pi by connecting it via USB - USB. A quote from the manual:
"USB is the easiest way to interface to PCs or advanced microcontrollers like a Raspberry Pi"

The Sabertooth also has a 'User Mode' in this mode the controller can accept two input methods such as R/C and Serial. The S2 input is connected to channel 5 on the R/C receiver and acts as a switch to set the mode to R/C or Serial control. What I am not clear about is whether this mode would work with a Raspberry Pi connected via USB or whether it would only work if connected to S1. S1 one is the Serial RX port so in this mode the Sabertooth could only receive signals, which I guess is what is needed.
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera

Moe
Posts: 230
Joined: Sun Jan 25, 2015 2:44 pm

Re: Sabertooth 2x32 Autonomous and R/C

Fri Apr 21, 2017 7:49 pm

I am doing something very similar. I have a Sabertooth 2x25 that I'm using to drive a robot with four wheelchair motors, two on each side/channel (yeah I know, it's on the limit). The Sabertooth is set to R/C and differential mode, so I can drive it like an R/C car with one channel controlling speed and the other doing steering. This bit works.

The RPi has a I2C PWM servo controller HAT that drives digital servos, and - I hope - will behave exactly like a two channel R/C receiver and drive the Sabertooth in the same way. I admit I have not yet tried this - the robot is big and lives in the garage, the development lab is in the dining room, and the two have not yet come together.

Mine doesn't have USB or a user mode, but I've installed a 2-way 3-pole manual switch that will switch S1 and S2 between the R/C receiver and the servo controller (and power up the receiver) so I shouldn't have to faff about with with DIP switches when changing mode.

If this doesn't work I would be open to serial or USB options, so will follow your progress with much interest.
Submarine communication systems engineer and amateur robot enthusiast.

User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 561
Joined: Sat Nov 02, 2013 2:06 pm

Re: Sabertooth 2x32 Autonomous and R/C

Fri Apr 21, 2017 9:34 pm

Moe;

Are you blogging the build?
I am building mine for two things. At first it will be a Robot for a project that I am building as part of a BCS Certificate in Teaching Primary Computing. It will be used in school to engage children and hopefully inspire them to start 'making'. It's not even built yet and I have a small cohort of lads interested in it. They were already working on a Moon Rover project :-) and are now thinking Robot Wars!!

I am blogging the chassis build and basic motorisation on the Project Dalek Forums:

http://www.projectdalek.com/index.php?/ ... lphas-nsd/

I will also blog it on my Wordpress blog here:

https://wordpress.com/posts/picodeandch ... dpress.com

It will be the bottom link entitled 'Project Robot'.
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera

Moe
Posts: 230
Joined: Sun Jan 25, 2015 2:44 pm

Re: Sabertooth 2x32 Autonomous and R/C

Sat Apr 22, 2017 12:16 am

I seem to need logins for both those links; will set myself up tomorrow and bookmark them. I love this sort of stuff - it's very, very difficult, but the sense of achievement when it works is correspondingly huge. Using it to inspire future engineers gives your project a tangible and worthy purpose.

My goals are rather less noble; my project has but two simple aims:
1. To keep me occupied in a way that doesn't involve TV or alcohol. I'm a professional engineer working on big projects that can get very boring for long periods, so the day-to-day technical challenges of the robot design helps to keep dementia at bay.
2. To protect the house when society collapses. I figure the only tactical advantage us geeks will have is the ability to build killer robots.
I haven't blogged anything yet; should probably start something when I get things working :D

If your project is a dalek, what are your plans for sensors? I assume you want the thing to track and target people?
Submarine communication systems engineer and amateur robot enthusiast.

User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 561
Joined: Sat Nov 02, 2013 2:06 pm

Re: Sabertooth 2x32 Autonomous and R/C

Sun Apr 23, 2017 4:29 pm

Moe, not sure about the Dalek Forums but you shouldn't need a login to look at my Wordpress pages. Maybe I sent you an edit link? Try this:

https://picodeandchips.wordpress.com/projects/
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera

Moe
Posts: 230
Joined: Sun Jan 25, 2015 2:44 pm

Re: Sabertooth 2x32 Autonomous and R/C

Sun Apr 23, 2017 9:48 pm

I can the page and click on the other links but the project robot one says 'invalid post address'
Submarine communication systems engineer and amateur robot enthusiast.

User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 561
Joined: Sat Nov 02, 2013 2:06 pm

Re: Sabertooth 2x32 Autonomous and R/C

Mon Apr 24, 2017 4:59 pm

Moe wrote:I can the page and click on the other links but the project robot one says 'invalid post address'
Ah yes it's empty :-) nothing added yet.

Just trying to borrow a 2.4Ghz Tx and Rx so I can test my motors.
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera

User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 561
Joined: Sat Nov 02, 2013 2:06 pm

Re: Sabertooth 2x32 Autonomous and R/C

Sun Apr 30, 2017 8:44 am

I have a couple of threads going covering various questions for this build but as a follow up to this one I have made some headway.
I spent most of the day working out how to connect my Sabertooth / Motors etc and re-looking at the code to send plain text serial commands.
For a python / serial solution In the end I opted to use webiopi as my original code did not work.
Once I installed webiopi, did some trial and error testing, fixed some errors in my code, got the right serial port name and corrected the DIP switches - WOOP WOOP I figured it all out and managed to run my motors wirelessly :-)

Annoyingly whilst doing this the serial port changed from ttyam0 to ttyam1 without anything extra plugged in?
You don't need to start webiopi unless you are using the web interface but it needs to be installed and if using USB you don't need to disable serial boot logging (if that's what it's called). Only need to disable it if using serial over the GPIO pins (I think) just check the webiopi tutorials.http://webiopi.trouch.com/Tutorial_Serial.html

Here's my working test code that simply runs through a loop spinning each motor fwd and back one at a time:

Code: Select all

#!/usr/bin/python3

import webiopi
from webiopi.devices.serial import Serial
from time import sleep

serial = Serial('ttyACM0', 9600) #enter correct port for serial

def loop():
    # write data to serial port

    for i in range (1, 5):
        serial.writeString("M1: 1023\r\n")
        print("M1 Fwd")
        sleep(2)
        serial.writeString("M1: 0\r\n")
        print("M1 Off")
        sleep(2)
        serial.writeString("M2: 1023\r\n")
        print("M2 Fwd")
        sleep(2)
        serial.writeString("M2: 0\r\n")
        print("M2 Off")
        sleep(2)
        serial.writeString("M1: -1023\r\n")
        print("M1 Reverse")
        sleep(2)
        serial.writeString("M1: 0\r\n")
        print("M1 Off")
        sleep(2)
        serial.writeString("M2: -1023\r\n")
        print("M2 Reverse")
        sleep(2)
        serial.writeString("M2: 0\r\n")
        print("M2 Off")

        if (serial.available() > 0):
            data = serial.readString()
            print(data)

        webiopi.sleep(1)

loop()
I am only a python beginner but I don't believe the if(serial.available) section is needed as I don't believe the Sabertooth is returning any serial data? Probably only needed if connecting via an Arduino and your code on the Arduino is configured to send back any data for either debugging or from sensors.
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera

User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 561
Joined: Sat Nov 02, 2013 2:06 pm

Re: Sabertooth 2x32 Autonomous and R/C

Fri May 05, 2017 2:40 pm

Anyone following or finding this thread I now have a fully working (well sort of) remote control robot using serial over USB.
Although I have borrowed a 2.4Ghz Tx / Rx I have not yet wired them up, instead I have opted to get a remote web interface working (which I have done before).

I am using webiopi to send the serial commands to the motor driver as well as using webiopi to send commands to a python program from a web page control panel (the remote control).

I am experiencing one issue at the moment which is when adding a USB web camera using mjpg-streamer to send a video stream to my web page. If I call the mjpg-streamer startup script from within my python code for some reason I can no longer send commands to my motor controller board?

Here is my working python code:

Code: Select all

#########################################################################################
# This is a programme to add a web based control of a Sabertooth 2 x 32Amp Motor Driver #
# Commands are sent to Raspberry Pi over a web page using webiopi                       #
# and interpretted within this program for transmission to the motor driver             # 
# In the initial setup serial commands are being sent over USB                          #
# If you wish send serial using the GPIO you need to install pigpio and                 #
# start the pigpio daemon by either entering pigpiod at a command prompt                #
# or running it automatically at startup                                                #
# as a CRON job                                                                         #
# Bill Harvey 05/05/17                                                                  #                                                                         
#########################################################################################

#!/usr/bin/python3

# import the neccessary libraries 
import webiopi # Import webiopi - software to communicate with a Rapsberry Pi over a web interface
from webiopi.devices.serial import Serial 
from time import sleep
import os

# configure the serial communications port (you may need to change this based on your port name / number
serial = Serial('ttyACM0', 9600) # this was the baud rate used in my test - poss could be higher

# Uncomment the following two lines if using the Pi GPIO
# import pigpio # pigpio is a custom module for controlling GPIO pins 
# pi = pigpio.pi #declare psuedo for pigpio commands

# define the webio macros which are needed to interpret commands from the web control panel

#@webiopi.macro
def stop():
        #number = 0
        serial.writeString("M1: 0\r\n")
        serial.writeString("M2: 0\r\n")
        print("M1 and M2 off") # print to terminal for debugging
        sleep(1) #not sure if the sleep is required so needs to be tested
        
#@webiopi.macro
def forward():
        number = 1
        serial.writeString("M1: -1023\r\n") # half speed
        serial.writeString("M2: -1023\r\n")
        print("M1 and M2 forward") # print to terminal for debugging
        sleep(1)
        
#@webiopi.macro
def left():
        number = 2
        serial.writeString("M1: -1023\r\n") # motor 1 forward full speed
        serial.writeString("M2: 1023\r\n") # motor 2 reverse full speed
        print("M1 forward and M2 reverse") # print to terminal for debugging
        sleep(1)
        
#@webiopi.macro
def right():
        number = 3
        serial.writeString("M1: 1023\r\n") # motor 1 reverse half speed
        serial.writeString("M2: -1023\r\n") # motor 2 forward half speed
        print("M1 reverse and M2 forward") # print to terminal for debugging
        sleep(1)
        
#@webiopi.macro
def backward():
        number = 4
        serial.writeString("M1: 1023\r\n") # motor 1 reverse half speed
        serial.writeString("M2: 1023\r\n") # motor 2 reverse half speed
        print("M1 and M2 reverse") # print to terminal for debugging
        sleep(1)

#@webiopi.macro
def servo_centre():
        number = 5
        print("servo centre") #print to terminal for debugging
        sleep(1)

#@webiopi.macro
def servo_left():
        number = 6
        print("servo left") #print to terminal for debugging
        sleep(1)

#@webiopi.macro
def servo_right():
        number = 7
        print("servo right") #print to terminal for debugging
        sleep(1)        
        
#@webiopi.macro
def led_on():
	number = 8
	print("LED on if fitted") #print to terminal for debugging
	sleep(1)
	
#@webiopi.macro
def led_off():
	number = 9
	print("LED off if fitted") #print to terminal for debugging
	sleep(1)
	
# Start the webiopi server
server = webiopi.Server(port=8000, login="coffin", password="coffin")

# Start the webcam video stream
# os.system("./streamer.sh")

# Register the macros
server.addMacro(stop)
server.addMacro(forward)
server.addMacro(left)
server.addMacro(right)
server.addMacro(backward)
server.addMacro(stop)
server.addMacro(servo_centre)
server.addMacro(servo_left)
server.addMacro(servo_right)
server.addMacro(led_on)
server.addMacro(led_off)

# Run default loop

webiopi.runLoop()

# Cleanly stop the server
server.stop()

Here is my html:

Code: Select all

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content = "height = device-height, width = 420, user-scalable = no" /> 
<title>COFFIN_Control_Panel</title>
<script type="text/javascript" src="/webiopi.js"></script>
<script type="text/javascript">

   	function stop() {
   	webiopi().callMacro("stop");
   	}
   
   	function forward() {
       webiopi().callMacro("forward");
    }

   	function left() {
       webiopi().callMacro("left");
    }

   	function right() {
       webiopi().callMacro("right");
    }

   	function backward() {
       webiopi().callMacro("backward");
    }

	function servo_centre() {
		webiopi().callMacro("servo_centre");
	}	
   	
   	function servo_left() {
       webiopi().callMacro("servo_left");
    }

	function servo_right() {
		webiopi().callMacro("servo_right");
	}
		
   function LED_On() {
       webiopi().callMacro("led_on");
    }
   
   function LED_Off() {
       webiopi().callMacro("led_off");
    }	

</script>


<style type="text/css">

.myButton {
   -moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
   -webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
   box-shadow:inset 0px 1px 0px 0px #ffffff;
   background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #ffffff), color-stop(1, #f6f6f6));
   background:-moz-linear-gradient(top, #ffffff 5%, #f6f6f6 100%);
   background:-webkit-linear-gradient(top, #ffffff 5%, #f6f6f6 100%);
   background:-o-linear-gradient(top, #ffffff 5%, #f6f6f6 100%);
   background:-ms-linear-gradient(top, #ffffff 5%, #f6f6f6 100%);
   background:linear-gradient(to bottom, #ffffff 5%, #f6f6f6 100%);
   background-color:#ffffff;
   -moz-border-radius:6px;
   -webkit-border-radius:6px;
   border-radius:6px;
   border:1px solid #dcdcdc;
   display:inline-block;
   cursor:pointer;
   color:#666666;
   font-family:Arial;
   font-size:15px;
   font-weight:bold;
   padding:6px 24px;
   text-decoration:none;
   text-shadow:0px 1px 0px #ffffff;
        width: 130px;
        height:30px;
        margin:1px;
}
.myButton:hover {
   background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #f6f6f6), color-stop(1, #ffffff));
   background:-moz-linear-gradient(top, #f6f6f6 5%, #ffffff 100%);
   background:-webkit-linear-gradient(top, #f6f6f6 5%, #ffffff 100%);
   background:-o-linear-gradient(top, #f6f6f6 5%, #ffffff 100%);
   background:-ms-linear-gradient(top, #f6f6f6 5%, #ffffff 100%);
   background:linear-gradient(to bottom, #f6f6f6 5%, #ffffff 100%);
   background-color:#f6f6f6;
        padding:6px 24px;
}
.myButton:active {
   color:#ff0000;
        position:relative;
   top:1px;
        padding:6px 24px;
}

</style>

</head>
<body>
<center><h2>COFFIN Control Panel</h2></center><br>


<center>
<table>
<tr><td colspan=3 align="center"><button class="myButton" onmousedown="forward()" onmouseup="stop()">Forward</button></td></tr>
<tr><td><button class="myButton" type="button" onmousedown="left()" onmouseup="stop()">Left</button></td>
<td><button class="myButton" type="button" onclick="stop()">Stop</button></td>
<td><button class="myButton" type="button" onmousedown="right()" onmouseup="stop()">Right</button></td></tr>
<tr><td colspan=3 align="center"><button class="myButton" type="button" onmousedown="backward()" onmouseup="stop()">Backward</button></td></tr>
<tr><td colspan=3 align="center"><button class="myButton" type="button" onmousedown="LED_On()" onmouseup="LED_Off()">LED_On</button></td></tr>
</table>
</center>

<center><h2>Sensor Control</h2></center><br>
<center>
<table>
<tr><td><button class="myButton" type="button" onclick="servo_left()">Scan Left</button></td>
<td><button class="myButton" type="button" onclick="servo_centre()">Centre</button></td>
<td><button class="myButton" type="button" onclick="servo_right()">Scan Right</button></td></tr>
</table>
</center>

<center><h2>RIP Cam</h2></center>
	<center><img id="streamimage" src="http://192.168.1.125:8080/?action=stream" /></center>
</body>
</html>
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera

User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 561
Joined: Sat Nov 02, 2013 2:06 pm

Re: Sabertooth 2x32 Autonomous and R/C

Sun May 07, 2017 5:29 pm

And here is hopefully a working link to my project blog?
https://picodeandchips.wordpress.com/20 ... t-project/
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera

chadk5utc
Posts: 7
Joined: Wed Dec 26, 2018 4:34 pm

Re: Sabertooth 2x32 Autonomous and R/C

Sun Jan 13, 2019 6:42 pm

I know and understand this thread is very old however Im hoping the OP still available as I have a few questions before I test this.
1 how refined is motor control ie all or nothing or does it start out slow and increase? I cant tell reading the code
2 have there been any newer developments to this or did it die?
I currently have an R/C controlled 2x32 weighing in about 150lbs with 5.8ghz FPV tx onboard but would like very much to add computer control and put it on my home network so that I can run this from the comfort of my laptop, lazy mans gate checker for the farm lol.

Thanks

GVianello
Posts: 1
Joined: Sat Feb 09, 2019 4:01 pm

Re: Sabertooth 2x32 Autonomous and R/C

Sat Feb 09, 2019 5:14 pm

I'm looking fir someone help me to build an autonomous drive system to automate rccar chassis that I produce, are you interested?

quote=chadk5utc post_id=1415799 time=1547404946 user_id=285158]
I know and understand this thread is very old however Im hoping the OP still available as I have a few questions before I test this.
1 how refined is motor control ie all or nothing or does it start out slow and increase? I cant tell reading the code
2 have there been any newer developments to this or did it die?
I currently have an R/C controlled 2x32 weighing in about 150lbs with 5.8ghz FPV tx onboard but would like very much to add computer control and put it on my home network so that I can run this from the comfort of my laptop, lazy mans gate checker for the farm lol.

Thanks
[/quote]

tazmoe
Posts: 1
Joined: Wed Feb 13, 2019 2:12 am

Re: Sabertooth 2x32 Autonomous and R/C

Wed Feb 13, 2019 2:17 am

Google "DIY Drones Rover" you will find all kinds of info and you can use a Pixhawk autopilot to drive your robot with real time telemetry feedback.

Return to “Automation, sensing and robotics”