Go to Post you must do whats best for the company...not yourself. - Greg Perkins [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 11-02-2009, 20:24
Alex_2487 Alex_2487 is offline
Registered User
AKA: Alex Korpi
no team
Team Role: Alumni
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Sayville, New York
Posts: 31
Alex_2487 is an unknown quantity at this point
Send a message via AIM to Alex_2487
chaging values on an axis/toogle switch

is thier a way to change the values that an axis gives out. right now i am using this code

BeaterBars->Set(GetZ());

and it gives out values -1.0 to 1.0. and we have no need for our system to run backwards. how would i change it to values 0.0 to 1.0.

also does anyone know how to program a toogle switch so we don't have to keep a button held down.
__________________
Events
2009 SBPLI Long Island Regional
2008 Deer Park Invitational, Championships- Galileo Division, SBPLI Long Island Regional
Awards
2009 Long Island Semifinalists
2008 Deer Park Invitational Finalist (353,1546), Long Island Regional Champion (2010,102),Highest Rookie Seed, Rookie Inspiration, Best Website, Website Excellence Award
2009 Record(2487): 5-9-1
2008 Record(2487): 23-10-3
Overall Record(2487): 27-19-4
www.wbsts.com/gnomes.html
Reply With Quote
  #2   Spotlight this post!  
Unread 11-02-2009, 20:39
Sentient's Avatar
Sentient Sentient is offline
Registered User
FRC #0639 (Code Red)
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Ithaca
Posts: 21
Sentient is on a distinguished road
Re: chaging values on an axis/toogle switch

You can clamp the joystick values from the joystick pretty easily.

float inputZ = stick->GetZ();
if(inputZ < 0.0)
inputZ = 0.0;

motor->Set(inputZ);

As for the toggle switch, what exactly are you using it for? If you are wanting to use a toggle switch that you on the driver station digital IO, you can just check the driver station inputs with driverStation->GetDigitalInput(channel);

EDIT: The above method for clamping would disregard anything below 0. If you want -1 to equal 0, 0.0 to equal 0.5, and 1.0 to equal 1.0, you can do this (although it would be very unintuitive for the driver):

motor->Set((stick->GetZ()+1.0)/2);

Last edited by Sentient : 11-02-2009 at 20:42.
Reply With Quote
  #3   Spotlight this post!  
Unread 11-02-2009, 20:55
Alex_2487 Alex_2487 is offline
Registered User
AKA: Alex Korpi
no team
Team Role: Alumni
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Sayville, New York
Posts: 31
Alex_2487 is an unknown quantity at this point
Send a message via AIM to Alex_2487
Re: chaging values on an axis/toogle switch

Quote:
Originally Posted by Sentient View Post
You can clamp the joystick values from the joystick pretty easily.

float inputZ = stick->GetZ();
if(inputZ < 0.0)
inputZ = 0.0;

motor->Set(inputZ);

As for the toggle switch, what exactly are you using it for? If you are wanting to use a toggle switch that you on the driver station digital IO, you can just check the driver station inputs with driverStation->GetDigitalInput(channel);

EDIT: The above method for clamping would disregard anything below 0. If you want -1 to equal 0, 0.0 to equal 0.5, and 1.0 to equal 1.0, you can do this (although it would be very unintuitive for the driver):

motor->Set((stick->GetZ()+1.0)/2);
we are using the throttle axis on the joystick so it will work program the second way


right now my code for a motor is this

if (Thirdjoystick->GetRawButton (2)==1 )
{
frontroller->set(-1.0);
}
else if (Thirdjoystick->GetRawButton (3)==1 )
{
frontroller->set(1.0)
}
esle
{
frontroller->set(0.0)
}

right now the motor is off when we turn on the robot and when we hold down button 2 it rruns backwards and button 3 runs forward. i want to be able to make it so the second driver doesnt need to hold down the button and can just press it to switch between forward and stop and on the other button switch between backward and stop.
__________________
Events
2009 SBPLI Long Island Regional
2008 Deer Park Invitational, Championships- Galileo Division, SBPLI Long Island Regional
Awards
2009 Long Island Semifinalists
2008 Deer Park Invitational Finalist (353,1546), Long Island Regional Champion (2010,102),Highest Rookie Seed, Rookie Inspiration, Best Website, Website Excellence Award
2009 Record(2487): 5-9-1
2008 Record(2487): 23-10-3
Overall Record(2487): 27-19-4
www.wbsts.com/gnomes.html

Last edited by Alex_2487 : 11-02-2009 at 21:50.
Reply With Quote
  #4   Spotlight this post!  
Unread 12-02-2009, 10:14
sircedric4's Avatar
sircedric4 sircedric4 is offline
Registered User
AKA: Darren
no team (The SS Prometheus)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2006
Location: Lousiana
Posts: 245
sircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond repute
Re: chaging values on an axis/toogle switch

Quote:
Originally Posted by Alex_2487 View Post
we are using the throttle axis on the joystick so it will work program the second way


right now my code for a motor is this

if (Thirdjoystick->GetRawButton (2)==1 )
{
frontroller->set(-1.0);
}
else if (Thirdjoystick->GetRawButton (3)==1 )
{
frontroller->set(1.0)
}
esle
{
frontroller->set(0.0)
}

right now the motor is off when we turn on the robot and when we hold down button 2 it rruns backwards and button 3 runs forward. i want to be able to make it so the second driver doesnt need to hold down the button and can just press it to switch between forward and stop and on the other button switch between backward and stop.

In this case you'll need to set a flag up. This will be in psuedocode but it will be something like:

You need to set a flag when the button is pressed, the problem is that the button is in an endless loop so you'll have to make sure you only poll the Buttonflag once each time the button is held down, so you'll need another flag for that.

Define a ButtonFirstflag
Define a Button2flag
Initialize the variables at the beginning:
Button2flag=false;
ButtonHeldflag = true;


if (Button2) {
if (ButtonFirstflag) {
if (!Button2flag) {
Button2flag = true;
} else {
Button2flag = false;
}
ButtonHeldflag = false;
}
ButtonHeldflag = true;

If (Button2flag) {
Motor = forward
} else {
Motor = stop
}

There maybe an easier means to do what you are asking, but this is what I use when I want to do what you are talking about. I hope I've helped.
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Joystick values (?) beefy1 Programming 1 23-12-2008 11:26
Joystick axis values in new controller koreabell Programming 7 17-12-2008 11:39
penalties values??? colin340 Rules/Strategy 4 08-03-2008 21:37
Need Help Wiring Micro Switch/Limiting Switch Windward Electrical 2 07-02-2006 18:26
Servo Values DanDon Motors 8 14-02-2005 15:49


All times are GMT -5. The time now is 13:01.

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