View unanswered posts | View active topics It is currently Thu Jun 21, 2018 12:33 pm

 Page 1 of 1 [ 10 posts ]
 Print view Previous topic | Next topic
Author Message
Novice

Joined: Mon Oct 13, 2008 6:29 pm
Posts: 75
Location: Florida, USA
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
Professor

Joined: Fri Sep 19, 2008 1:22 am
Posts: 200

_________________
Jeff McBride
Benson Robotics Club

Sun Oct 26, 2008 4:42 pm
Expert

Joined: Mon Oct 06, 2008 6:30 pm
Posts: 176
Location: Netherlands

_________________
My most recent blog: A grain of sugar

Sun Oct 26, 2008 6:01 pm
Expert

Joined: Tue Oct 14, 2008 7:16 pm
Posts: 171
Location: Investigating an unidentified ship sighted in Sector 31428
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
Rookie

Joined: Thu Oct 02, 2008 12:35 pm
Posts: 12
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.

_________________
Gracious Professionalism. Their standard, our standard.

Mon Nov 10, 2008 6:13 pm
Expert

Joined: Mon Oct 06, 2008 6:30 pm
Posts: 176
Location: Netherlands
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

Joined: Wed Jan 24, 2007 10:42 am
Posts: 620
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
Rookie

Joined: Wed Mar 05, 2008 11:37 am
Posts: 3
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
Expert

Joined: Tue Oct 14, 2008 7:16 pm
Posts: 171
Location: Investigating an unidentified ship sighted in Sector 31428
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
Expert

Joined: Mon Oct 06, 2008 6:30 pm
Posts: 176
Location: Netherlands
[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
Display posts from previous:  Sort by
 Page 1 of 1 [ 10 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning