Go to Post Minnesota could pioneer the idea of suspending a field 20 feet above the other field and have true double decker events. - PayneTrain [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 16-02-2007, 12:02
GMAdan's Avatar
GMAdan GMAdan is offline
Team member turned mentor
AKA: Daniel A. Cobar
FRC #1881 (GAMMA Elite)
Team Role: Mentor
 
Join Date: Dec 2006
Rookie Year: 2006
Location: Paterson, NJ
Posts: 110
GMAdan has a spectacular aura aboutGMAdan has a spectacular aura about
Send a message via AIM to GMAdan
how to limit pwm on easyc

how to you limit pwm values so a motor will never go full speed. i want my range to be 55-200. i have seen it done on mplab but i can't figure it out on easyc
  #2   Spotlight this post!  
Unread 16-02-2007, 13:13
oddjob oddjob is offline
Registered User
no team
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Earth
Posts: 118
oddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to behold
Re: how to limit pwm on easyc

Code:
if(pwm_value > 200)
pwm_value = 200;
if(pwm_value<55)
pwm_value = 55;
setPWM(port,pwm_value)
  #3   Spotlight this post!  
Unread 16-02-2007, 13:22
Francis-134's Avatar
Francis-134 Francis-134 is offline
Lifer
FRC #0190 (Gompei and the Herd)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Worcester, MA
Posts: 602
Francis-134 has a reputation beyond reputeFrancis-134 has a reputation beyond reputeFrancis-134 has a reputation beyond reputeFrancis-134 has a reputation beyond reputeFrancis-134 has a reputation beyond reputeFrancis-134 has a reputation beyond reputeFrancis-134 has a reputation beyond reputeFrancis-134 has a reputation beyond reputeFrancis-134 has a reputation beyond reputeFrancis-134 has a reputation beyond reputeFrancis-134 has a reputation beyond repute
Re: how to limit pwm on easyc

The easiest way would be to set up an if statement where if the motor value > 200, set the motor to 200. You would take the value from the joystick (use an OI to PWM block) and instead of setting it to a PWM port, set it to a variable. Then, with an if statement, limit the values to whatever range you want. Finally, send that variable to a setpwm block with that variable set as the speed.
__________________

Email | Twitter | Facebook | YouTube | Twitch
iTunes Podcast | Snapchat

A proud alumnus of teams 134 and 40 || Mentor of Team 190 || Director of Fun for BattleCry@WPI
  #4   Spotlight this post!  
Unread 17-02-2007, 21:52
ncosens ncosens is offline
Registered User
FRC #2163
 
Join Date: Feb 2007
Location: Lapeer
Posts: 1
ncosens is an unknown quantity at this point
Re: how to limit pwm on easyc

If you want to control the speed of a PWM from a joystick controller then just limiting the final value sent the PWM based on boundaries is a waste. Since 127 is neutral, and you want 200 to be your max, moving your joystick beyond the raw 200 position will do nothing further to the value. You might as well not even limit it.

Instead, try scaling it. Find the difference between your raw value and 127, and divide it by the difference between the the max raw value and 127, then multiply that by the difference between your "new" max and 127.

example: {n = int; d = double}

Code:
nRaw_Value = GetOIAInput (yourport, youraxis);
dFinal_Value_Intermediate = (nRaw_Value - 127) / (maxraw -127);
dFinal_Value_Intermediate = dFinal_Value_Intermediate * (yourmax - 127);
nFinal_Value = dFinal_Value_Intermediate + 127
SetPWM ( yourPWMport, nFinal_Value );
With a joystick on port 1 and the y-axis the numbers would go like this:

Code:
nRaw_Value = GetOIAInput (1, 2);
dFinal_Value_Intermediate = (220 - 127) / (255 - 127);
                          = 93 / 128;
                          = 0.7265625;
nFinal_Value_Intermediate = 0.7265625 * (200 -127);
                          = 0.7265625 * 73;
                          = 53.0390625;
nFinal_Value = 53 + 127;
             = 180;
SetPWM(1, 180);
Of course, there are some casting issues with this example, but you get the idea. I use this technique a lot with my TI-84 Plus calculator graphics.
  #5   Spotlight this post!  
Unread 17-02-2007, 23:38
charrisTTI charrisTTI is offline
Ramblin' Wreck
AKA: Charles Harris
FRC #0623
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2003
Location: Vienna, VA
Posts: 106
charrisTTI has a spectacular aura aboutcharrisTTI has a spectacular aura about
Send a message via AIM to charrisTTI
Re: how to limit pwm on easyc

Implicit in the examples listed above is that you cannot use the tank or arcade motor control functions in easy c to accomplish what you want. You need to code the relationship between joystick and pwm yourself.
__________________
FRC 623 2003,2004,2005,2006,2007,2008, 2009, 2010, 2011
FRC 1900 2007
FVC 60 and 193 2006
FVC 3271 2007
FTC 226 and 369 2008, 2009, 2010, 2011
FTC 3806 2010
  #6   Spotlight this post!  
Unread 17-02-2007, 23:41
GMAdan's Avatar
GMAdan GMAdan is offline
Team member turned mentor
AKA: Daniel A. Cobar
FRC #1881 (GAMMA Elite)
Team Role: Mentor
 
Join Date: Dec 2006
Rookie Year: 2006
Location: Paterson, NJ
Posts: 110
GMAdan has a spectacular aura aboutGMAdan has a spectacular aura about
Send a message via AIM to GMAdan
Re: how to limit pwm on easyc

well what i want to limit the speed for is not the drivetrain but the arm it moves a bit too fast. So i just want a way to keep the value from passing 50-200.
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
Kevin's PWM 13-16 Code in easyC PRO Kingofl337 Programming 0 02-02-2007 09:03
Is there a limit to how many balls we can pick up? waialua359 Rules/Strategy 8 27-01-2006 05:06
PWM Extention Cables: 4 Shall Be the Limit Joe Johnson FIRST Tech Challenge 4 12-04-2005 23:33
How do you wire a limit switch? JMH Electrical 1 16-02-2005 17:44
How do you set a speed limit on the servo Fares Programming 6 01-01-2003 15:04


All times are GMT -5. The time now is 00:31.

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