ROBOTC.net forums
http://robotc.net/forums/

Joystick Sensitivity
http://robotc.net/forums/viewtopic.php?f=52&t=7626
Page 1 of 1

Author:  RobotDaddy [ Tue Jan 07, 2014 1:32 pm ]
Post subject:  Joystick Sensitivity

We built an arm type device and i have the joysticks set to control the arms and the other joysticks set to control the wheels, but the joysticks for the arms are too strong. They flail all over and flip over the robot. I want the joysticks to be less sensitive so the motors run at half power. I tried using buttons for it in my code, but it doesn't seem to work. My code is really simple because when I try to change the threshold or anything like that then the whole robot begins being all spastic and shaking. It's not the motors or anything. Can anyone give me some advice? Thank You. Here is my code:

Code:
#pragma config(Hubs,  S1, HTMotor,  none,     none,     none)
#pragma config(Hubs,  S2, HTMotor,  none,     none,     none)
#pragma config(Hubs,  S3, HTMotor,  none,     none,     none)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Sensor, S2,     ,               sensorI2CMuxController)
#pragma config(Sensor, S3,     ,               sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C1_1,     motorF,        tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C1_2,     motorG,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S2_C1_1,     motorD,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S2_C1_2,     motorE,        tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S3_C1_1,     motorH,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S3_C1_2,     motorI,        tmotorTetrix, openLoop, reversed)
#include "JoystickDriver.c"

task main()
{
    while(true)
    {
        getJoystickSettings(joystick);
        motor[motorD] = joystick.joy1_y1;
        motor[motorE] = joystick.joy1_y2; //Motor E is Reversed

        getJoystickSettings(joystick);
        motor[motorF] = joystick.joy2_y1;
        motor[motorG] = joystick.joy2_y1; //Motor G is reversed

        motor[motorH] = joystick.joy2_y2;
        motor[motorI] = joystick.joy2_y2; //Motor I is reversed


        if(joy2Btn(5))
        {
                motor[motorF] = -50;
                motor[motorG] = -50;
        }

        if(joy2Btn(6))
        {
                motor[motorH] = -50;
                motor[motorI] = -50;
        }

        if(joy2Btn(7))
                motor[motorF] = 50;
                motor[motorG] = 50;
        }
        if(joy2Btn(8))
        {
                motor[motorH] = 50;
                motor[motorI] = 50;
        }
      }



Attachments:
File comment: Here is the attached file if you rather have that
CompBot.c [1.88 KiB]
Downloaded 320 times

Author:  cookthebook [ Tue Jan 07, 2014 2:01 pm ]
Post subject:  Re: Joystick Sensitivity

I would suggest to only set the joystick values to the motors if they reach a certain point, the joysticks can come to a rest at like 1 or -1, thus making the motor move a bit, this is similar to what I do:

Code:
 
if(abs(joystick.joy1_y1) > 40){
        motor[motorD] = joystick.joy1_y1;
        motor[motorE] = joystick.joy1_y2; //Motor E is Reversed
}
else{
        motor[motorD] = 0;
        motor[motorE] = 0;
}


And then for your buttons, I have never used the joy2Btn(5) as a boolean, so I'm not sure what effect that has, I have always done:

Code:
if(joy2Btn(5) == 1){//1 means pressed
   //do code
}

if(joy2Btn(5) == 0){//0 is not pressed
   //do code or lack there of
}


So hopefully that may fix some of your issues :-)

Author:  JohnWatson [ Tue Jan 07, 2014 2:14 pm ]
Post subject:  Re: Joystick Sensitivity

cookthebook wrote:
I would suggest to only set the joystick values to the motors if they reach a certain point, the joysticks can come to a rest at like 1 or -1, thus making the motor move a bit, this is similar to what I do:

Code:
 
if(abs(joystick.joy1_y1) > 40){
        motor[motorD] = joystick.joy1_y1;
        motor[motorE] = joystick.joy1_y2; //Motor E is Reversed
}
else{
        motor[motorD] = 0;
        motor[motorE] = 0;
}


This is correct, and is called a threshold or deadband value (although 40 is usually a little bit high for these values, and a value of ~10 may work better). This doesn't help with the speed issues, but rather with the joystick not returning to a dead center positional value of 0. To cut the applied power being sent to the motor(s) in half, simply divide the joystick values in half before assigning them to the motors (I've made some other tweaks to the code as well, such as checking each joystick's value individually):

Code:
 
if(abs(joystick.joy1_y1) > 10){
        motor[motorD] = joystick.joy1_y1/2;
}
else{
        motor[motorD] = 0;
}

if (abs(joystick.joy1_y2) > 10){
        motor[motorE] = joystick.joy1_y2/2; //Motor E is Reversed
}
else{
motor[motorD] = 0;
}




Quote:
And then for your buttons, I have never used the joy2Btn(5) as a boolean, so I'm not sure what effect that has, I have always done:

Code:
if(joy2Btn(5) == 1){//1 means pressed
   //do code
}

if(joy2Btn(5) == 0){//0 is not pressed
   //do code or lack there of
}


So hopefully that may fix some of your issues :-)


Since the buttons only return a 0 or a 1, you can use them directly as a boolean condition in control statements without having to compare them to a 0 or a 1; this is one of the nice features of buttons and switches (and, if you research it enough, is why things like DIP switches and jumpers were so popular on earlier computers). However, writing out the comparison doesn't hurt, and can actually form a good coding habit as well as making it easier to see what the code is doing.

Author:  MHTS [ Tue Jan 07, 2014 3:44 pm ]
Post subject:  Re: Joystick Sensitivity

Which motor(s) is the arm? What is your arm design? Would it be able to hold position if the motor power is cut? If it can't, what if you push the joystick up to raise the arm and then release the joystick? The motor power becomes zero and the arm will drop like a dead bird? These are important questions to answer in order to determine how to write code to control it.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/