Go to Post I applaud teams that make signs of all kinds - giant numbers, large banners, humongous heads. It's all good. - Ryan Dognaux [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 11-02-2006, 13:27
Unholy Unholy is offline
electrical / makeshift programmer
AKA: Daniel
FRC #1402
Team Role: Programmer
 
Join Date: Feb 2006
Rookie Year: 2002
Location: Orlando, FL
Posts: 21
Unholy is an unknown quantity at this point
Send a message via AIM to Unholy
issues limiting a joystick input

I'm trying to limit the speed in a motor through programming in in such a way that when the joystick is fully deflected, i will only get a response of, let's say, 93 instead of 0, and 150 instead of 255. The way the joystick is set to work is that it won't be engaged unless the trigger is closed. Initially, as soon as I clicked the joystick trigger, my value would change automatically to 0 from 127 using a command looking like this:


if (p3_sw_top == 1 )
{
pwm03 = (((p3_x) *2) / 10)
}

Initially I thought I had issues with the trim, but I checked the trim using pwm03 = p3_x;, set it to neutral, went back to the line above, and as soon as I clicked again, my value was 0 again.
I'd appreciate any help I can help, and sorry for this noobish question
-Danny
  #2   Spotlight this post!  
Unread 11-02-2006, 13:56
CronosPrime1 CronosPrime1 is offline
Registered User
FRC #0321
 
Join Date: Jan 2006
Location: Hyperspace
Posts: 53
CronosPrime1 is an unknown quantity at this point
Re: issues limiting a joystick input

I don't exactly understand your question - please clarify.
__________________
  #3   Spotlight this post!  
Unread 11-02-2006, 14:13
Unholy Unholy is offline
electrical / makeshift programmer
AKA: Daniel
FRC #1402
Team Role: Programmer
 
Join Date: Feb 2006
Rookie Year: 2002
Location: Orlando, FL
Posts: 21
Unholy is an unknown quantity at this point
Send a message via AIM to Unholy
Re: issues limiting a joystick input

Quote:
Originally Posted by CronosPrime1
I don't exactly understand your question - please clarify.
ok. I have a motor running on the p3_x port. The pwm input has a range from 0-255, but I can't use that. What I'd like to have would be to have a range of 100-154 (so to say) while I'm using the joystick, so when it's fully deflected to the highest value, the pwm input would be 154 instead of 255, and when I deflect it to the lowest value, the pwm would be 100 instead of 0. I think I was approaching the problem wrong using multipliers.
  #4   Spotlight this post!  
Unread 11-02-2006, 14:19
Oumonkey's Avatar
Oumonkey Oumonkey is offline
Master of the If statement
AKA: Josh Tyus
FRC #1555 (Pulse)
Team Role: Programmer
 
Join Date: Jun 2005
Rookie Year: 2005
Location: Monon, IN
Posts: 50
Oumonkey has a spectacular aura aboutOumonkey has a spectacular aura about
Re: issues limiting a joystick input

I guess this wasn't what ya needed, oh well. You saved me a few hours of anger now. I love you..... j/k but thanks you help me. Now I can finish the rest of my code.

we use something similar in our codes. Except ours is opposite, to get it to max.
if (pwm16>154) pwm16 = 154;
if (pwm16<100) pwm16 = 100;
Try that, I don't know much about programming, but ours also has a little trim so if its within 3 or 4 points of 127 it equals 127;
if ((pwm16<130)&&(pwm16>124)) pwm16 = 127;
I'm pretty sure thats what I have, I don't have my code with me but it should work, if anyone else can point out a mistake go ahead....I almost forgot the semi-colons
__________________

Last edited by Oumonkey : 11-02-2006 at 21:52.
  #5   Spotlight this post!  
Unread 11-02-2006, 15:49
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: issues limiting a joystick input

Let's do some basic arithmetic here.

Right now, joystick input J maps to PWM output O on a 1-1 basis; that is, your transfer function is:

O = J;

You want to redefine this, so imagine the above equation as a line with slope 1. Slope*J is going to be your new PWM value. Intuitively, this would yield:

O = SLOPE * J;

However, you have to take into account the fact that the motor and joystick is centered around 127:

signed int J_S;
...
J_S = J - 127;
O = SLOPE * J_S + 127;

Thus, to have the max PWM value be 190, you would do:

signed int J_S;
...
J_S = J - 127;
O = J_S / 2 + 127;

Since 127/2+127 = 190.5 ~= 190. Because of the integer math on the PIC, you can reduce this to the general form:

#define SLOPE_NUM 1
#define SLOPE_DEN 2
signed int J_S;
...
J_S = J - 127;
O = J_S * SLOPE_NUM / SLOPE_DEN + 127;

Now simply manipulate SLOPE_NUM and SLOPE_DEN to come up with the slope you want (actual slope is SLOPE_NUM/SLOPE_DEN).

This lets you limit the PWM to whatever you'd like while still giving your joystick a full range of motion.

Last edited by Jared Russell : 11-02-2006 at 15:51.
  #6   Spotlight this post!  
Unread 11-02-2006, 15:54
Calvin Calvin is offline
Registered User
no team
 
Join Date: Feb 2005
Location: Portland OR
Posts: 105
Calvin has a spectacular aura aboutCalvin has a spectacular aura about
Re: issues limiting a joystick input

so when:

input -> output
x -> y
0 -> 100
255 -> 155

Slope: y2-y1/x2-x1
Slope: 155-100/255-0
Slope: (11/51)

y = mx + b
y = 11/51x + b
100 = 11/51(0) + b
b = 100

so: y = (11/51)x + 100
so: pwm16 = ((11/51)*p3_x) + 100;

PHP Code:
if (p3_sw_top == 1)
{
     
pwm16 = ((11/51)*p3_x) + 100;
}
else
{
      
pwm16 p3_x;


Last edited by Calvin : 11-02-2006 at 16:01.
  #7   Spotlight this post!  
Unread 11-02-2006, 16:05
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: issues limiting a joystick input

Almost. It is MUCH easier to re-center the joystick around 0 first:

int p3_x_mod = (int)p3_x - 127;

You should then fix the "b" part of y=mx+b to 127 so that no matter what, not moving the joystick is neutral. Also, with integers, (11/51) will be evaluated first as ZERO, screwing everything up. Using p3_x_mod, which is an int, in the expression below also makes sure that you don't overflow the size of an unsigned char.

Try:

pwm16 = (11*p3_x_mod/51) + 127;

Your final code would look something like:

Code:
int p3_x_mod;
...

if( p3_sw_top )
{
  p3_x_mod = (int)p3_x - 127;
  pwm16 = (11*p3_x_mod/51) + 127;
}
else
{
  pwm16 = p3_x;
}
The code you wrote works fine on paper, but it suffers from both the rounding to zero and size overflow problems.

Last edited by Jared Russell : 11-02-2006 at 16:09.
  #8   Spotlight this post!  
Unread 12-02-2006, 19:53
Unholy Unholy is offline
electrical / makeshift programmer
AKA: Daniel
FRC #1402
Team Role: Programmer
 
Join Date: Feb 2006
Rookie Year: 2002
Location: Orlando, FL
Posts: 21
Unholy is an unknown quantity at this point
Send a message via AIM to Unholy
Re: issues limiting a joystick input

thank you to everyone who posted. I really appreciate the help ^_^. I will try some of this stuff when I get back to school.
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
2006 CMUcam2 Code Kevin Watson Programming 81 10-02-2007 20:17
Free programming help Cuog Programming 24 24-01-2006 16:43
Change joystick to pwm mapping Joe Lewis Programming 3 30-03-2005 19:27
Changing 1 joystick code to 2 (rookie team) Brawler006 Programming 5 20-02-2004 17:00
joystick problem archiver 2000 12 23-06-2002 23:08


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

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