Hi there!
So I am using this code to control my robot with a wireless PS2 gaming controller.
// 4/24/14
//Sketch uses the input from the left analog stick of a ps2 gaming controller
// to control a motor driver requiring inputs from 1000-2000us
#include <Servo.h>
#include <PS2X_lib.h> //for v1.6
PS2X ps2x; // create PS2 Controller Class
int error = 0;
byte type = 0;
byte vibrate = 0;
Servo Signal1;
Servo Signal2;
int Input1 = 1500;// creates servo object
int Input2 = 1500;
void setup()
{
Serial.begin(57600);
Signal1.attach(4); //the pins for the servo control
Signal2.attach(5);
error = ps2x.config_gamepad(13,11,10,12, true, true); //setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
if(error == 0)
Serial.println("Controller found! You may now send commands");
else if(error == 1)
Serial.println("No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips");
else if(error == 2)
Serial.println("Controller found but not accepting commands. see readme.txt to enable debug. Visit www.billporter.info for troubleshooting tips");
else if(error == 3)
Serial.println("Controller refusing to enter Pressures mode, may not support it. ");
type = ps2x.readType();
switch(type)
{
case 0:
Serial.println("Unknown Controller type");
break;
case 1:
Serial.println("DualShock Controller Found");
break;
}
}
//My sabortooth motordriver can use the two signals 1000us-2000us to control the two motors
void loop()
{
if(error == 1) //skip loop if no controller found
{
return;
}
else
{
ps2x.read_gamepad(false, 0);
Input1 = map(ps2x.Analog(PSS_LY), 0, 255, 2000, 1000);
Signal1.writeMicroseconds(Input1);
//Serial.print ("Input1: ");
// Serial.println (Input1);
Input2 = map(ps2x.Analog(PSS_LX), 0, 255, 2000, 1000);
Signal2.writeMicroseconds(Input2);
//Serial.print ("Input2: ");
// Serial.println (Input2);
delay(8);
}
}
Problem is the controls are so sensitive that it is very difficult to control my robot. A minor movement on the analog stick causes it to shoot across the room! I need to create something similar to "expo" on rc transmitters. A quick explanation:
""Expo" is short for "Exponential" and basically gives you slop in the movement of the controller sticks. With expo disabled (the default value), if you move the stick 50% of the distance between the center and the edge, the servo will move 50%. Move it 75% an the servo moves 75%. Easy, right?
Now, give the Expo a value and the softening factor comes in. Let's say you move the stick 30%. Instead of the servo moving 30% of its range, it will move some degree less. The higher your expo setting, the less the servo will move near the center-stick area."
I've been looking at the SoftPWM library (https://code.google.com/p/rogue-code/wiki/SoftPWMLibraryDocumentation). Perhaps it could come into play. Any suggestions on how to get this bot under control?
Thanks!!!!
Walter