Hi all,
First post, sorry if i waste your time. I'm struggling a bit with understanding how to stop my actuators within certain values. For example, i would like to have my actuator stop going forward after it extends about 1/2 of it's length. The issue i'm having is that it is fully extended, or fully reversed, nothing in between.
I've got two sabertooth 2x5's in simplified serial with slave setup. I've confirmed this works (not confirmed with pots connected). I know my pot voltage is changing as well, with the voltage decreasing as the actuator extends.
I've attached my code below:
#include <SoftwareSerial.h>
/*****************************************************
* DIP Switches as per the wizard:
* - NiMh Battery
* - TTL RS232
* - Simplified Serial Mode
* - Two Saberteeth connected
* - 9600 baudrate
*
* Pin 1 - ON
* Pin 2 - OFF
* Pin 3 - ON
* Pin 4 - OFF
* Pin 5 - ON
* Pin 6 - OFF
****************************************************/
// Labels for use with the Sabertooth 2x5 motor controller
// Digital pin 18 is the serial transmit pin to the
// Sabertooth 2x5
#define SABER_TX_PIN 18
// NOT USED (but still init'd)
// Digital pin 19 is the serial receive pin from the
// Sabertooth 2x5
#define SABER_RX_PIN 19
// Set to 9600 through Sabertooth dip switches
#define SABER_BAUDRATE 9600
// Simplified serial Limits for each motor
//64 is soft stop
#define SABER_MOTOR1_FULL_FORWARD 127
#define SABER_MOTOR1_FULL_REVERSE 1
//192 is soft stop
#define SABER_MOTOR2_FULL_FORWARD 255
#define SABER_MOTOR2_FULL_REVERSE 128
// Motor level to send when issuing the full stop command
#define SABER_ALL_STOP 0
SoftwareSerial SaberSerial = SoftwareSerial( SABER_RX_PIN,
SABER_TX_PIN );
// Setting up the actuator pots, connected to a8-a11:
//analogRead(Actuatorx) reads in the value from the pin.
int Actuator1 = A8; // selects the input pins for the actuator potentiometer
int Actuator2 = A9;
int Actuator3 = A10;
int Actuator4 = A11;
// places to store actuator loaction values
int Actuator1Value = 0;
int Actuator2Value = 0;
int Actuator3Value = 0;
int Actuator4Value = 0;
//setting up select pins. 52 in motor controller 1, 53 is motor controller 2
int MC1 = 52;
int MC2 = 53;
void initSabertooth( void )
{
// Init software UART to communicate
// with the Sabertooth 2x5
pinMode( SABER_TX_PIN, OUTPUT );
SaberSerial.begin( SABER_BAUDRATE );
// 2 second time delay for the Sabertooth to init
delay( 2000 );
// Send full stop command
SaberSerial.write(byte(SABER_ALL_STOP));
//setting up pinmodes for select pins
pinMode(MC1, OUTPUT);
pinMode(MC2, OUTPUT);
// setting pinmode for analog pins, is this needed?
//pinMode(Actuator4,INPUT);
/*pinMode(Actuator2,INPUT);
pinMode(Actuator3,INPUT);
pinMode(Actuator4,INPUT);
*/
}
void setup( )
{
initSabertooth( );
}
void loop ( )
{
// setting a halfway position
//LOW disables both motor controllers
//HIGH enables both motor controllers
// only using one MC right now
digitalWrite(MC1, LOW);
digitalWrite(MC2, HIGH);
//Experimenting with act #3
Actuator3Value = analogRead(Actuator3);
if (Actuator3Value > 500)
// {
SaberSerial.write(byte(SABER_MOTOR1_FULL_FORWARD));
// }
}
Thanks for the input.