View unanswered posts | View active topics It is currently Thu Jul 31, 2014 9:28 pm






Reply to topic  [ 10 posts ] 
Dead Zone 
Author Message
Novice

Joined: Mon Oct 13, 2008 6:29 pm
Posts: 75
Location: Florida, USA
Post Dead Zone
could someone post code on creating a joystick dead zone, thanks in adv.

_________________
PHUHS Robotics
Team 516 FTW

Daytona Robofest Winning Alliance Captain
Daytona Robofest Inspire Award


Sun Oct 26, 2008 3:25 pm
Profile
Professor

Joined: Fri Sep 19, 2008 1:22 am
Posts: 200
Post Re: Dead Zone
Take a look at the TankArcade.c example in the thread: http://www.robotc.net/forums/viewtopic.php?f=33&t=826.

_________________
Jeff McBride
Benson Robotics Club


Sun Oct 26, 2008 4:42 pm
Profile
Expert
User avatar

Joined: Mon Oct 06, 2008 6:30 pm
Posts: 176
Location: Netherlands
Post Re: Dead Zone
Code:
const int deadzone=18;
int desiredspeed;

if (abs(joystick.joy1_y1)>deadzone)
{
  desiredspeed=joystick.joy1_y1/1.28;
  if (desiredspeed>0)
    desiredspeed-=deadzone;
  else
    desiredspeed+=deadzone;
}
else
  desiredspeed=0;
motor[motorA]=desiredspeed;


_________________
My most recent blog: A grain of sugar


Sun Oct 26, 2008 6:01 pm
Profile WWW
Expert
User avatar

Joined: Tue Oct 14, 2008 7:16 pm
Posts: 171
Location: Investigating an unidentified ship sighted in Sector 31428
Post Re: Dead Zone
You could also do it this way
Code:
long speed[2] = {0, 0};
void speedCalc()
{
    while(true)
    {
        getJoystickSettings(joystick);
        if(joystick.joy1_y1 >= 20 || joystick.joy1_y1 <= -20) //Creates a dead zone by ignoring any values from -20 to 20
        {
            long val = 0.000023727307*(joystick.joy1_y1^3) + 0.000048054645*(joystick.joy1_y1^2) + 0.3987059273*joystick.joy1_y1 - 0.0033576988; //This equation scales the speed but for some reason it only returns half the proper value
            speed[0] = 2*val; // So here we multiply it by two
        }
        else
        {
            speed[0] = 0;
        }
        if((joystick.joy1_y2 >= 20) || (joystick.joy1_y2 <= -20)) //Creates a dead zone by ignoring any values from -20 to 20
        {
            long val2 = 0.000023727307*(joystick.joy1_y2^3) + 0.000048054645*(joystick.joy1_y2^2) + 0.3987059273*joystick.joy1_y2 - 0.0033576988;
            speed[1] = 2*val2;
        }
        else
        {
            speed[1] = 0;
        }
    }
}

_________________
Captain, Head programmer, School of the Arts, Silverbots Robtics Team #2890
Code:
using namespace System;
using namespace Genius;
using namespace Personality;
public ref class Nerd : Geek, IAnserable
{
    Geek::Type brainMode = Geek::Type::Programmer;
}


Sun Oct 26, 2008 8:34 pm
Profile
Rookie

Joined: Thu Oct 02, 2008 12:35 pm
Posts: 12
Post Re: Dead Zone
Hey I have made a Program for the dead zone, but every time I run it, it just never works correctly, because the robot will never move. Here is the program:
Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  none,     none)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorNormal, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,     ,              tmotorNone, openLoop)
#pragma config(Motor,  mtr_S1_C2_2,     ,              tmotorNone, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"

task main()
{
  while(true)
  {
    if ((joystick.joy1_y1 <= 30 || joystick.joy1_y1 >= -30))
    {
      motor[motorD] = 0;
    }
    else if ((joystick.joy1_y1 >= 30 || joystick.joy1_y1 <= -30))
    {
      getJoystickSettings(joystick);
      motor[motorD] = joystick.joy1_y1;
    }
    if ((joystick.joy1_y2 <= 30) || (joystick.joy1_y2 >= -30))
    {
      motor[motorE] = 0;
    }
    else if ((joystick.joy1_y2 >= 20) || (joystick.joy1_y2 <= -20))
    {
      getJoystickSettings(joystick);
      motor[motorE] = joystick.joy1_y2;
    }
  }
}


If you can help, we would appreciate it very much. :programmer: :eek: :breakcomputer:

_________________
Gracious Professionalism. Their standard, our standard.


Mon Nov 10, 2008 6:13 pm
Profile
Expert
User avatar

Joined: Mon Oct 06, 2008 6:30 pm
Posts: 176
Location: Netherlands
Post Re: Dead Zone
Your program uses joystick.joy1_y2 to tell your motor how fast to rotate. Things like joystick.joy1_y2 are variables and need to be inialized before they can be used. In this case you do this with the getJoystickSettings(joystick) function. If you don't initilize it you'll get a zero value (if you are lucky).
Also, everytime before you use the variable you have to make sure it is updated (if you want to). Again, you do this with the getJoystickSettings(joystick) function.
You do use this function, but it is at the end of the while loop in a conditional branche. But it might never be executed. Moving this statement to the top of your while loop will solve your problem.

_________________
My most recent blog: A grain of sugar


Mon Nov 10, 2008 7:37 pm
Profile WWW
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 601
Post Re: Dead Zone
you should move the "GetJoystickValues" function to right after the "while(true)" loop is started.

Example (snippet):

Code:
while(true)
  {
    getJoystickSettings(joystick);
   
    if ((joystick.joy1_y1 <= 30 || joystick.joy1_y1 >= -30))
    {
      motor[motorD] = 0;
    }
    else if ((joystick.joy1_y1 >= 30 || joystick.joy1_y1 <= -30))
    {
      motor[motorD] = joystick.joy1_y1;
    }

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Wed Nov 12, 2008 1:49 pm
Profile
Rookie

Joined: Wed Mar 05, 2008 11:37 am
Posts: 3
Post Re: Dead Zone
Everyone is correct so far as far as getting the values from the joystick. However the real problem is with the logic in your first if statement. It reads:

if ((joystick.joy1_y1 <= 30 || joystick.joy1_y1 >= -30))
{
motor[motorD] = 0;
}

The issue is that every single value for joystick.joy1_y1 will be <= 30 OR >= -30. So this if statement always evaluates to true and motorD will never move.

What you want to do is change it to use && (AND) instead of || (OR).


Fri Nov 14, 2008 1:22 am
Profile
Expert
User avatar

Joined: Tue Oct 14, 2008 7:16 pm
Posts: 171
Location: Investigating an unidentified ship sighted in Sector 31428
Post Re: Dead Zone
Please note that it should be >= 30 and <= -30 other wise your motors will only work for a very small range of the joystick, thusly,
Code:
if((joystick.joy1_y1 >= 30) || (joystick.joy1_y1 <= -30))
{
    motor[motorD] = joystick.joy1_y1;
}
else
{
    motor[motorD] = 0;
}

While you could use an else if to explictly test for values within the dead zone it becomes redundant because if it isn't outside the dead zone it's inside it so just an else is necessary.

_________________
Captain, Head programmer, School of the Arts, Silverbots Robtics Team #2890
Code:
using namespace System;
using namespace Genius;
using namespace Personality;
public ref class Nerd : Geek, IAnserable
{
    Geek::Type brainMode = Geek::Type::Programmer;
}


Sat Nov 15, 2008 8:57 pm
Profile
Expert
User avatar

Joined: Mon Oct 06, 2008 6:30 pm
Posts: 176
Location: Netherlands
Post Re: Dead Zone
[quote="Atlantisbase"]
Code:
if ((joystick.joy1_y1 >= 30) || (joystick.joy1_y1 <= -30))
{
    motor[motorD] = joystick.joy1_y1;
}
else
{
    motor[motorD] = 0;
}


The if statement of this code is correct. However, You cannot simple pass the joystick value to the motor. The range of the joystick goes from -128 to 128. The motor has a valid range of -100 to 100. Therefore you'll have to devide the joystick range by 1.28 (resulting in a value between -100 and 100) before assigning it to the motor.

Also, please note that using this code the minimum speed of the motor =30 or -30. I do not know if this is what you want. But suppose you want both a deadzone and the possiblility to have a minimum speed below 30 then you'll have to correct for this as well.

_________________
My most recent blog: A grain of sugar


Sun Nov 16, 2008 5:49 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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.