View unanswered posts | View active topics It is currently Fri Nov 28, 2014 8:09 pm






Reply to topic  [ 4 posts ] 
Joystick Sensitivity 
Author Message
Rookie
User avatar

Joined: Thu Dec 05, 2013 12:57 pm
Posts: 8
Location: Las Vegas
Post 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 143 times
Tue Jan 07, 2014 1:32 pm
Profile WWW
Rookie
User avatar

Joined: Wed Jan 09, 2013 11:48 pm
Posts: 42
Location: Saint Paul, MN
Post 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 :-)

_________________
Head Programmer FTC Team 6699, Tempest

Code:
<Life>
   Fun
</Life>


Tue Jan 07, 2014 2:01 pm
Profile WWW
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 610
Post 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.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Tue Jan 07, 2014 2:14 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post 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.


Tue Jan 07, 2014 3:44 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.