Go to Post Free hugs are excellent things. - Eugenia Gabrielov [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 22-01-2012, 15:04
dmitch's Avatar
dmitch dmitch is offline
Chief Head Electrical Guy
AKA: Daniel Mitchell
FRC #1997 (Stag Robotics)
Team Role: Programmer
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Bishop Miege High School
Posts: 142
dmitch is a jewel in the roughdmitch is a jewel in the roughdmitch is a jewel in the roughdmitch is a jewel in the rough
Help Needed with some Simple Programming

Hey there, I am a fairly new programmer and so I just need some help with a few main problems. First of all, how do we put a deadband into the joystick so that we have no ghosting? In pseudocode that would be:
If joystick value < .1 and >-.1
joystick value = 0.
where .1 would be our "dead" area limit.

also how would we set up a motor to run to either the value of an axis on a joystick or a button? more pseudocode:

if button 2 is true then run motor 1 at 1/4 speed
or something like :
set motor 1 value to axis 3 value

i know how i would have to phrase it just not the actual syntax or location.
__________________
Reply With Quote
  #2   Spotlight this post!  
Unread 22-01-2012, 21:34
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Help Needed with some Simple Programming

Your questions imply that you don't know C++. If that's the case, why are you using it to program your robot? You'll need some assistance close at hand in order to do an effective job.

What is your programming experience? Depending on what you already know, there might be different ways to tell or show you what you need to do.
Reply With Quote
  #3   Spotlight this post!  
Unread 23-01-2012, 12:54
dmitch's Avatar
dmitch dmitch is offline
Chief Head Electrical Guy
AKA: Daniel Mitchell
FRC #1997 (Stag Robotics)
Team Role: Programmer
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Bishop Miege High School
Posts: 142
dmitch is a jewel in the roughdmitch is a jewel in the roughdmitch is a jewel in the roughdmitch is a jewel in the rough
Re: Help Needed with some Simple Programming

I have programmed one year in LabView and one year in C++. The old programmer who taught me programming wasnt a very good teacher and so i came away with hardly any knowledge and because of that towards the end of last build season we asked for help from another local team who only knew c++, so we switched. Its turned out to work very well but I need still need help with programming.
__________________
Reply With Quote
  #4   Spotlight this post!  
Unread 23-01-2012, 14:03
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,170
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Help Needed with some Simple Programming

Post your C++ code and I'll show you how to modify it to insert a dead band.
Reply With Quote
  #5   Spotlight this post!  
Unread 23-01-2012, 15:44
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 671
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Help Needed with some Simple Programming

Regarding deadband, we use the following set of macros:
Code:
#ifndef DEADBAND_INPUT_THRESHOLD
  #define DEADBAND_INPUT_THRESHOLD  0.10
#endif
#define DEADBAND(n,t)           ((ABS(n) > (t))? (n): 0)
#define DEADBAND_INPUT(n)       DEADBAND(n, DEADBAND_INPUT_THRESHOLD)

 
float x = DEADBAND_INPUT(joystick.GetX());
float y = DEADBAND_INPUT(-joystick.GetY());
__________________
Reply With Quote
  #6   Spotlight this post!  
Unread 23-01-2012, 17:33
dmitch's Avatar
dmitch dmitch is offline
Chief Head Electrical Guy
AKA: Daniel Mitchell
FRC #1997 (Stag Robotics)
Team Role: Programmer
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Bishop Miege High School
Posts: 142
dmitch is a jewel in the roughdmitch is a jewel in the roughdmitch is a jewel in the roughdmitch is a jewel in the rough
Re: Help Needed with some Simple Programming

I tried the code that you gave but its not working, what specific location does it need to be in inside my robot code? Also is there a way to add the deadband directly to the reading from the axis via the GetRawAxis or GetX/GetY commands? Or do macros work the best?
__________________
Reply With Quote
  #7   Spotlight this post!  
Unread 23-01-2012, 17:46
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 671
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Help Needed with some Simple Programming

You can put the macros in a separate file (e.g. macros.h) and then include it in your C++ file. For example:
Code:
In MyRobot.cpp:
#include "macros.h"
 
class MyRobot: public SimpleRobot
{
}
Or you can put the macros directly in your MyRobot.cpp file replacing the #include line.
And what do you mean when you said it's not working? Did it give you compile error or you have no error compiling and the code is downloading and running but it doesn't give you the deadband effect?

You don't have to use macros. You can expand them directly inline to your GetX(), GetY() calls but it would be a lot of typing and high risk of typos.
__________________
Reply With Quote
  #8   Spotlight this post!  
Unread 23-01-2012, 17:53
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 671
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Help Needed with some Simple Programming

Oh, I forgot one thing. We defined our own ABS macro as well. So the macros should be:
Code:
#ifndef DEADBAND_INPUT_THRESHOLD
  #define DEADBAND_INPUT_THRESHOLD  0.10
#endif
#define ABS(n)                  (((n) < 0)? -(n): (n))
#define DEADBAND(n,t)           ((ABS(n) > (t))? (n): 0)
#define DEADBAND_INPUT(n)       DEADBAND(n, DEADBAND_INPUT_THRESHOLD)
 
 
float x = DEADBAND_INPUT(joystick.GetX());
float y = DEADBAND_INPUT(-joystick.GetY());
__________________
Reply With Quote
  #9   Spotlight this post!  
Unread 23-01-2012, 18:11
dmitch's Avatar
dmitch dmitch is offline
Chief Head Electrical Guy
AKA: Daniel Mitchell
FRC #1997 (Stag Robotics)
Team Role: Programmer
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Bishop Miege High School
Posts: 142
dmitch is a jewel in the roughdmitch is a jewel in the roughdmitch is a jewel in the roughdmitch is a jewel in the rough
Re: Help Needed with some Simple Programming

where do the lines

float x = DEADBAND_INPUT(joystick.GetX());
float x = DEADBAND_INPUT(-joystick.GetY());

go?

when I wrote them in my code right below the rest of the code (which is directly under the #include "WPILib.h") i could not build the code without getting the error "'leftStick' was not declared in this scope". leftStick is what our 1st joystick is named, we have 2 for tank drive. I also switched out joystick in the above code for leftStick.
__________________
Reply With Quote
  #10   Spotlight this post!  
Unread 23-01-2012, 18:27
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 671
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Help Needed with some Simple Programming

I assume if you are using the SimpleRobot template, you will have something similar to the code below. Since I don't have Wind River in front of me, I am writing the code from my memory, so some names may be wrong and the code may not be exactly the same as the template but it gives you an idea where to put things.
Code:
#include "WPILib.h"
#include "macros.h"   //Or put the macros here directly.
 
class MyRobot: public SimpleRobot
{
    Joystick leftStick;
    Joystick rightStick;
    RobotDrive drive;
 
    MyRobot():
        leftStick(1),   //Please use correct Joystick port
        rightStick(2),  //Please use correct Joystick port
        drive(1, 2)     //Please use correct PWM channels
    {
    }
    ...
    ...
    void OperatorControl()
    {
        while (IsEnable() && IsOperatorControl())
        {
            float leftPower = DEADBAND_INPUT(-leftStick.GetY());
            float rightPower = DEADBAND_INPUT(-rightStick.GetY());
            drive.TankDrive(leftPower, rightPower);
            ...
            ...
            Wait(0.05);
        }
    }
};
__________________

Last edited by mikets : 23-01-2012 at 18:35.
Reply With Quote
  #11   Spotlight this post!  
Unread 26-01-2012, 00:15
Tommy.Brown's Avatar
Tommy.Brown Tommy.Brown is offline
Lead Programmer
FRC #1477 (Texas Torque)
Team Role: Programmer
 
Join Date: Jul 2011
Rookie Year: 2011
Location: The Woodlands
Posts: 27
Tommy.Brown is an unknown quantity at this point
Re: Help Needed with some Simple Programming

Here is how you apply the deadband:

I assume that you already have the Joystick created, I am just gonna call it joystickcontroller.
And I am going to throw it all inside a method for functionality.

#include "math.h"
// Make sure you have that ^^^^

float DriverController::GetSpeedAxis()
{
float val = -joystickcontroller->GetY();
if( fabs(val) <= SPEED_AXIS_DEADBAND)
val = 0;
return val;
}//GetSpeedAxis

SPEED_AXIS_DEADBAND is a constant.... can be replaced by any number
The fabs call is the call for absolute value. This only works if the deadband that you want to set is the same for both the positive and negative values on the joystick. Since the deadband is the same in both the positive and negative direction, then by using the fabs call we can eliminate some needless code.

The motor code that you would want:
I am going to use Victor for this example, can be easily switched to work with a Jaguar just by changing the words Victor to Jaguar. I am going to call the joystick method that I gave to you earlier on this comment to get the value from the joystick. Lets just pretend they are in the same class for now.

Victor *vic = new Victor(VICTOR_PORT);
vic->Set(GetSpeedAxis());

Now what that did is take the value from the joystick and assign that -1 to 1 value to the Victor which then controls the motor itself.

To assign it a value as to whether a button is pressed:

Victor *vic = new Victor(VICTOR_PORT);
if(joystickcontroller->GetRawButton(1))
vic->Set(1);
else
vic->Set(0);

the value 1 when I called GetRawButton is the button that you wish to get, the button configuration are different for each different type of controller.

If you need any more help just message me.
__________________
FRC Team 1477 - Texas Torque
The Woodlands, Texas
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 03:02.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi