Decreasing sensitivity of my PS2 controlled bot

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? :astonished:

Thanks!!!!

Walter

    Input1 = map(ps2x.Analog(PSS_LY), 0, 255, 2000, 1000);

What proof can you offer that the Analog() method returns a value in the range 0 to 255?

The other values are the speed to set the (continuous rotation, not really a) servo to. If you want the robot to go slower, use two values equally closer to 1500 as the to range.

When I print the value of that the function to the serial monitor it is always between 0 and 255. Is an analog input not 0-225 under any circumstance?

The robot functions as it should. It is just too sensitive to be controlled with ease... I need the sensitivivity of the analog stick to be exponential, in other words input values near the center position of stick will effect less motion in my robot.

Walter

Is an analog input not 0-225 under any circumstance?

No. The values returned by analogRead(), for instance, are between 0 and 1023.

The robot functions as it should. It is just too sensitive to be controlled with ease... I need the sensitivivity of the analog stick to be exponential, in other words input values near the center position of stick will effect less motion in my robot.

Then, map(), which is a linear function, is not what you want to be using.

Ah, good bit of info to store away for future projects!

Any advice on how to create an exponential map. I am aware of the "pow" function, but I can't any detailed info on how to use it or exponential mapping.

Thanks!!

Walter