Go to Post I always mean what I say. I just don't always say what I mean. - dlavery [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 17-02-2015, 17:14
Ozuru's Avatar
Ozuru Ozuru is offline
It's always the programmer's fault.
no team
 
Join Date: May 2013
Rookie Year: 2010
Location: Earth
Posts: 268
Ozuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to behold
Axis/Slider Scale

Hi,

Currently I'm having an issue with the slider of my Logitech joystick. The range is from -1 to 1 and I need to convert it to be from 0 to 1 rather than -1 to 1. How would I go about doing this? I'm using the Logitech Extreme 3D Pro and the axis number is 3. I'm using Java but I figured this is a language-wide issue, hence the post here.

Thanks!
  #2   Spotlight this post!  
Unread 17-02-2015, 17:20
Jared's Avatar
Jared Jared is offline
Registered User
no team
Team Role: Programmer
 
Join Date: Aug 2013
Rookie Year: 2012
Location: Connecticut
Posts: 602
Jared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond repute
Re: Axis/Slider Scale

Code:
(stick.get() + 1) / 2
  #3   Spotlight this post!  
Unread 17-02-2015, 17:24
vps vps is offline
Registered User
FRC #3021 (The Agency)
Team Role: Programmer
 
Join Date: Mar 2013
Rookie Year: 2011
Location: United States
Posts: 30
vps is an unknown quantity at this point
Re: Axis/Slider Scale

In my experience, I've found that the slider has been unreliable. So, just watch out buddy.
  #4   Spotlight this post!  
Unread 17-02-2015, 17:32
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,101
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Axis/Slider Scale


Quote:
Originally Posted by Ozuru View Post
The range is from -1 to 1 and I need to convert it to be from 0 to 1 rather than -1 to 1.
Quote:
Originally Posted by Jared View Post
(stick.get() + 1) / 2
Jared gave you the answer.

If you are interested, here's the algebra to solve that kind of problem, for any input and output range, assuming you want a linear conversion from input to output:

Let x be the input and y be the output.

You want a linear conversion, so use the equation for a line:

y = mx + b

When x is -1 you want y to be 0:

0 = m(-1) + b ....(Equation1)

When x is 1 you want y to be 1:

1 = m(1) + b .....(Equation2)

You have 2 equations with two unknowns, so solve them.

Add the two equations:

1 = 2b .....=>..... b = (1/2)

Subtract Equation1 from Equation2:

1 = 2m .....=>..... m=(1/2)

So the conversion is y = (1/2)x + (1/2) = (x+1)/2


  #5   Spotlight this post!  
Unread 17-02-2015, 20:21
Ozuru's Avatar
Ozuru Ozuru is offline
It's always the programmer's fault.
no team
 
Join Date: May 2013
Rookie Year: 2010
Location: Earth
Posts: 268
Ozuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to behold
Re: Axis/Slider Scale

Quote:
Originally Posted by Jared View Post
Code:
(stick.get() + 1) / 2
Quote:
Originally Posted by Ether View Post





Jared gave you the answer.

If you are interested, here's the algebra to solve that kind of problem, for any input and output range, assuming you want a linear conversion from input to output:

Let x be the input and y be the output.

You want a linear conversion, so use the equation for a line:

y = mx + b

When x is -1 you want y to be 0:

0 = m(-1) + b ....(Equation1)

When x is 1 you want y to be 1:

1 = m(1) + b .....(Equation2)

You have 2 equations with two unknowns, so solve them.

Add the two equations:

1 = 2b .....=>..... b = (1/2)

Subtract Equation1 from Equation2:

1 = 2m .....=>..... m=(1/2)

So the conversion is y = (1/2)x + (1/2) = (x+1)/2


Thanks for that information and thanks for the great explanation, Ether. I hadn't thought of it that way (as a linear equation pair) but that actually makes sense.

Thank you!
  #6   Spotlight this post!  
Unread 17-02-2015, 20:48
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,679
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Axis/Slider Scale

Quote:
Originally Posted by Ozuru View Post
The range is from -1 to 1 and I need to convert it to be from 0 to 1 rather than -1 to 1.
While I understand that the problem is solved, i'm still rather intrigued -- why did you feel the need to do this; have default be 0.5, and have the joystick(s) serve as a throttle to that?
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Closed Thread


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 21:07.

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