Go to Post Building a 'bot is kinda like washing your hair, but instead of "rinse, lather, repeat"... you should "engineer, test, repeat". - Andy Baker [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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 21-03-2010, 22:06
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
Servo control with a joystick

Hello.

My team wants me to get a servo rigged to be controlled with a joystick. How do I convert joystick values (-1 thru. 1) to servo values (0 thru. 1)?
Reply With Quote
  #2   Spotlight this post!  
Unread 21-03-2010, 22:33
TubaMorg TubaMorg is offline
Programmermechanicalelect ricalcoach
AKA: Dan
FRC #1480 (Robatos Locos)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Houston
Posts: 450
TubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond repute
Re: Servo control with a joystick

Use the Servo class.
It has two methods you can use:

set(double value) where value = 0.0 to 1.0 for full range of motion

setAngle(double degrees) where degrees = position of the servo...values in excess of allowable range of motion simply saturate to the servo limit. The API assumes that the kit servos are linear.

So to answer your question. Since the joys run from -1 to 1, you can simply use a multiple for the set method:

Code:
Servo servo = new Servo(1);//Servo in PWM port 1
double servoIn = (joy.getX() +1)*0.5;

// Command to servo
servo.set(servoIn);


That should do it.
__________________
I don't need a signature.
Reply With Quote
  #3   Spotlight this post!  
Unread 22-03-2010, 02:00
FRC4ME FRC4ME is offline
Registered User
FRC #0339
 
Join Date: Feb 2008
Rookie Year: 2007
Location: Fredericksburg, VA
Posts: 324
FRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant future
Re: Servo control with a joystick

FYI, the general formula for scaling one range of values to another is:

Code:
newValue = newMax + (newMax - newMin) * (oldValue- oldMax) / (oldMax - oldMin)
In this case, oldMin and oldMax are -1 and 1, respectively (the joystick range), while newMin and newMax are 0 and 1, respectively (the servo range).
__________________
Go directly to queue. Do not pass pit.
Reply With Quote
  #4   Spotlight this post!  
Unread 22-03-2010, 20:02
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
Re: Servo control with a joystick

Thanks!

Just to verify:

Code:
    public double convert(double input) {
        //newValue = newMax + (newMax - newMin) * (oldValue- oldMax) / (oldMax - oldMin)
        input = 1 + (1 - 0) * (input- 1) / (1 - -1);
        return input;
    }
Reply With Quote
  #5   Spotlight this post!  
Unread 23-03-2010, 09:04
TubaMorg TubaMorg is offline
Programmermechanicalelect ricalcoach
AKA: Dan
FRC #1480 (Robatos Locos)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Houston
Posts: 450
TubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond repute
Re: Servo control with a joystick

Quote:
Originally Posted by Robototes2412 View Post
Thanks!

Just to verify:

Code:
    public double convert(double input) {
        //newValue = newMax + (newMax - newMin) * (oldValue- oldMax) / (oldMax - oldMin)
        input = 1 + (1 - 0) * (input- 1) / (1 - -1);
        return input;
    }
You can verify it by plugging in your input extremes (-1 to +1). I haven't had my coffee yet, but it doesn't seem like -1 converts to 0. Why not try the one I posted? KISS
__________________
I don't need a signature.
Reply With Quote
  #6   Spotlight this post!  
Unread 09-05-2010, 19:31
Jeremy Germita's Avatar
Jeremy Germita Jeremy Germita is offline
Co-Advisor/Lead Engineering Mentor
AKA: wood is good. plastic is fantastic.
FRC #5012 (Gryffingear) / (Antelope Valley FIRST Teams)
Team Role: Coach
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Lancaster, CA
Posts: 284
Jeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond repute
Re: Servo control with a joystick

I'm probably REALLY late to the party, but here's the solution I was taught.

double servOut = (stick.getRawAxis(1) + 1) / 2;

-1.0 becomes 0 and +1.0 becomes 1.0
__________________
Drive Coach Team 5012 Gryffingear / Antelope Valley FIRST teams / EWCP - (2013 - Current)
Student / Driver / Programmer / CAD - FRC Team 399: Eagle Robotics / FTC Team 72: GarageBots - (2009 - 2013)
Los Angeles Region FTC FTA/CSA/Head Ref
[FF] FIRST Pick
2014 FTC Los Angeles Regional Compass Award Winner.

2017 - San Diego Regional / Sacramento Regional / Las Vegas Regional
2016 - Los Angeles Regional Creativity + Winners (1197, 987, 5012) / Las Vegas Regional Team Spirit + SF (5012, 5851, 5049) / Galileo Subdivision
2015 - Inland Empire QF (597, 5012, 4413) / Las Vegas Imagery + Winners (148, 987, 5012) / Newton Subdivision and World Champions (118, 1678, 1671, 5012)
2014 - Inland Empire Rookie All Star + Highest Rookie Seed + SF (2339, 1967, 5012) / Las Vegas Rookie All Star / Galileo Division Imagery
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
Problem with servo control Jake The Man NI LabVIEW 2 09-02-2010 23:23
Joystick-Servo control Lumit NI LabVIEW 1 08-02-2010 23:21
Camera servo control off of the Joystick axes m3rc1l3ss NI LabVIEW 5 13-03-2009 20:00
We need help with joystick control Team ICE #1611 Control System 4 24-01-2005 15:57
how do i control a piston with a joystick Ryan Foley Programming 2 27-05-2003 17:13


All times are GMT -5. The time now is 11:16.

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