Hi, I really need some help on how to start my programming for the Arduino Leonardo to make the 4wd1 autonomous. I need some clear guidelines so I could actually start programming. Thanks for the help.
You’ll need to provide more details such as:
- Which motor controller are you using?
- How do you have everything setup / configured?
- Which sensors do you have and where are they placed?
- What are your objectives for autonomous motion?
- any other relevant information…
The motor controller that I am actually using is a Sabertooth 2x12. I am also currently having problems with the set up. There was no sensor given to me. The objective of the the autonomous motion is to move 1m in a straightline through the use of IMU. As of now I have measured the duty cycle for each command like “forward” “reverse” “left” “right”. Since I am very new to this I really am not clear on what should I actually do. I really want to learn so I really need help.
I have done the set up as described:
S1 to arduino pin10 ( for signal wires)
S2 to arduino pin11
sabertooth ground connected to gnd of arduino
red wire connected to vin.
Now I wanted to know if there is a sample code about controlling the motors using PWM values.
Thanks.
Consider using the Sabertooth libraries for Arduino:
dimensionengineering.com/info/arduino
This should save you a lot of time.
I actually tried using this code but it does not work on my 4wd1. I am thinking if its about the connection.
I want to clarify what is the meaning of hardware serial TX connected to s1.
Thanks for the reply.
// Jolty Sample for Packet Serial
// Copyright © 2012 Dimension Engineering LLC
// See license.txt for license details.
#include <Sabertooth.h>
Sabertooth ST(128); // The Sabertooth is on address 128. We’ll name its object ST.
// If you’ve set up your Sabertooth on a different address, of course change
// that here. For how to configure address, etc. see the DIP Switch Wizard for
// Sabertooth - dimensionengineering.com/dat … /start.htm
// SyRen - dimensionengineering.com/dat … /start.htm
// Be sure to select Packetized Serial Mode for use with this library.
//
// On that note, you can use this library for SyRen just as easily.
// The diff-drive commands (drive, turn) do not work on a SyRen, of course, but it will respond correctly
// if you command motor 1 to do something (ST.motor(1, …)), just like a Sabertooth.
//
// In this sample, hardware serial TX connects to S1.
// See the SoftwareSerial example in 3.Advanced for how to use other pins.
void setup()
{
Serial.begin(9600); // 9600 is the default baud rate for Sabertooth packet serial.
}
void loop()
{
ST.motor(1, 127); // Go forward at full power.
delay(2000); // Wait 2 seconds.
ST.motor(1, 0); // Stop.
delay(2000); // Wait 2 seconds.
ST.motor(1, -127); // Reverse at full power.
delay(2000); // Wait 2 seconds.
ST.motor(1, 0); // Stop.
delay(2000);
}
The problem is that on Leonardo the Serial object refers to the USB connection where io pins 0 and 1 go Serial1 object. Not sure how or if their library deals with it.
Edit I think you may be able to pass &Serial1 as second parameter to constructer of sabertooth object.
Kurt
Thanks Kurt !
For now im testing using arduino uno .But do you have any idea or somehow like a sample code on how to control the sabertooth using PWM values? So far now im using the servo method to make it move forward and backward.
Yes. Im referring to that. I was actually given this project and the first step that was instructed was to measure the pwm signals(pulse width,duty cycle) first from controlling using RC Controller then use the values that I got to create a program/code to make it autonomous.
As for code for a rover, you might check out my thread: viewtopic.php?t=8543&p=85426#p85426
There is a zip file for an Arduino Rover that I believe I left such that you could configure it for Packet Serial or RC…
Kurt
Hi Kurt !
From reading your thread I found out that your using a BotBoarduino. May I know what is it about? And do I just copy and paste your code to my program. I am now trying to understand your code but Im having such a hard time. I really hope you could help me out in some explanations.
Hi,
The Botboarduino (lynxmotion.com/c-153-botboarduino.aspx) is an Arduino Duemilanove compatible micro-controller that is built to the standard Lynxmotion/Basic Micro form factor.
It has 3 pin servo connectors for most of the pins, plus buttons, leds, speaker…
As for explaining code, I will try to help with any specific questions you have.
Kurt
Kurt, since I am using an arduino leonardo, how can I make use of your code to implement on my board. Can you give me a rough what are the pin configurations? And upon seeing your codes, the program is not an autonomous right? Can you give me bits and peices of what I need to alter from your code to actually make it an autonomous program?
const int leftmotor = 9;
void setup() {
pinMode(leftmotor, OUTPUT);
}
void loop() {
analogWrite(leftmotor, 127);
delay(500);
}
i am currently using this code to drive the motors forward.
My switch settings is as follows:
1-ON
2-ON
3-OFF
4-OFF
5-OFF
6-ON
and the connections are:
s1 to pin9
s1(ground) to gnd of arduino
I have read that if my switch settings are as follow, the s1 will only control m1. but when i tried it out s1 controls both the motors.
HELP!
If I am reading your switch settings properly, you have the Sabertooth in Analog mode. Note: I have never used analog mode so take this with a grain of salt
the command analogWrite does not output an analog value, but instead outputs some PWM mode, that with some external hardware (RC circuit)you could probably convert to an analog value. Others who have more recent electrical experience could probably explain better. What I did in my code was to use the Servo class to generate the appropriate pulses to be in servo PWM mode. Actually I used my own hacked up version that added some features, like a timed change of pulse widths…
As I mentioned earlier, I think the program from DE may work if on the Leonardo if you passed in a pointer to the Serial1 object.
Kurt
How can I pass in a pointer to the serial1 object? I actually is in a confused mode since I am not so familiar in programming. Earlier today, I was told to follow an example of analogwrite and connect to an oscilloscope to get appropriate values but I am still unaware of why I need to do that.
What if I wanted to use the duty cycle i got from measuring when its being controlled by an RC controller? What method should I use to actually makes it look as if its an RC Controller?
First, I took a look at the most recent version of their library and it looks like they already handle the Leonardo by detecting it for you with the default constructor. When you are not sure what they are doing, the best thing to do is to look at the header files and source files to get hints on what is going on.
But if they had not done this, you would use the second form of the constructor. That is your code may have something like: Sabertooth ST(128);
Instead it would look like: Sabertooth ST(128, Serial1);
Now for Servo RC stuff, you should look up postings like what is a servo… There are some in the Servo forum here. One points up to a writeup done by the previous Lynxmotion owners: lynxmotion.com/images/html/servo01.htm.
There are many ways to generate this type of signal. The simplest, but limited way is to hard code it up something like:
#define PWUS 1500 // about the standard center point for pulses
#define PWCYCLE 20000-1500 // get to about 50 cycles per second...
#define PIN 9
pinMode (PIN, OUTPUT);
digitalWrite(PIN, LOW);
loop:
digitalWrite(PIN, HIGH); // Start the high cycle
delayMicroseconds(PWUS); // Delay appropriate time
digitalWrite(PIN, LOW); // Put it back low
delayMicroseconds(PWCYCLE); // delay enough time to start the next cycle
goto loop;
Note: I typed this on fly so could have issues. Also the accuracy of the delayMicrosecnds for this long of a time may not be good… But this should give you an approximation…
You could hack in multiple servos into this loop, by adding their write high delay write low like the first pin and also subtract their high time from the cycle delay such that you continue to get about 50 cycles per second…
Again this is not the best approach for accuracy. Better to use hardware support. You can set up to use system timers, PWM… to do this on some pins, which you can get pretty good results with, but it takes some work. Somewhere between these approaches is to simply use the servo library. Look at the arduino reference for details on how to use.
Kurt
I have tried putting your code and editing it but the sabertooth moves are varying, sometimes it will be fast and both the wheels are not moving in the same direction. What do you mean by hardware support? How can i set up to use PWM on some pins?
here is the edited code from you;
#define PWUS 1500 // about the standard center point for pulses
#define PWCYCLE 20000-1500 // get to about 50 cycles per second…
#define PIN 9
void setup()
{
pinMode (PIN, OUTPUT);
digitalWrite(PIN, LOW);
}
void loop()
{
digitalWrite(PIN, HIGH); // Start the high cycle
delayMicroseconds(PWUS); // Delay appropriate time
digitalWrite(PIN, LOW); // Put it back low
delayMicroseconds(PWCYCLE); // delay enough time to start the next cycle
}