Go to Post "We'll fix that in programming" - EStokely [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 13-01-2008, 19:51
team877's Avatar
team877 team877 is offline
Registered User
FRC #0877 (Cub Robotics)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2001
Location: North Dakota
Posts: 52
team877 is an unknown quantity at this point
Controller Speed programming

I want to be able to have my robot only going so fast when the variables are between like 127 to 200 but when the variable exceeds 200 it returns to beening the normal variable. How can I do this in easyC?


Example:
-if pwm1 is between 127<200 set it to 150
-but once pwm1 is < 200 go back to equaling its correct variable

Last edited by team877 : 13-01-2008 at 19:55.
  #2   Spotlight this post!  
Unread 13-01-2008, 20:02
tseres's Avatar
tseres tseres is offline
obsessed with FIRST...
FRC #1565 (Think Tank Tech)
Team Role: Leadership
 
Join Date: Apr 2007
Rookie Year: 2007
Location: Cambridge, ON
Posts: 305
tseres is a glorious beacon of lighttseres is a glorious beacon of lighttseres is a glorious beacon of lighttseres is a glorious beacon of lighttseres is a glorious beacon of lighttseres is a glorious beacon of light
Re: Controller Speed programming

not sure about easyC, but the code woud look like this:

if((pwm1>127) && (pwm1<200)){
pwm1=150;
}
else if(pwm1>200){
pwm1=pwm1;
}


the last "if" is somewhat unnecessary, but i put it there to show you. i'm not sure, but in easyc can you still edit the actual code? if so, this should work.

PS
i dont use easyC because it has the word 'easy' in it
__________________


  #3   Spotlight this post!  
Unread 13-01-2008, 20:02
Gamer930's Avatar
Gamer930 Gamer930 is offline
Team 930 and 171 Alumni
AKA: Justin
no team
Team Role: Alumni
 
Join Date: Mar 2002
Rookie Year: 2002
Location: New Berlin, WI
Posts: 388
Gamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to behold
Re: Controller Speed programming

if(pwm01 < 200 && pwm01 >127)
{
pwm01 = 150;
}
else if(pwm01 > 200)
{
pwm01 = p1_y
}

There is Else and ElseIf blocks under Program Flow
__________________
2010 to Present, Scorekeeper/Field Power Volunteer for FRC/FTC/FLL
2005 - 2010, Team 171 College Mentor
2002 - 2005, Team 930 Student

Last edited by Gamer930 : 13-01-2008 at 20:03. Reason: added easyC reference
  #4   Spotlight this post!  
Unread 14-01-2008, 00:35
JohnC's Avatar
JohnC JohnC is offline
my other name is nigel
FRC #0360 (360 Revolution)
Team Role: Programmer
 
Join Date: Mar 2005
Rookie Year: 2005
Location: user_routines.c
Posts: 100
JohnC is a jewel in the roughJohnC is a jewel in the roughJohnC is a jewel in the roughJohnC is a jewel in the rough
Send a message via AIM to JohnC
Re: Controller Speed programming

The above two examples don't look like they will work... this code should work copied and pasted (assuming you want your Port 1 joystick to control pwm01):
Code:
if(p1_y > 127) {
  pwm01 = 150;
}

if(p1_y > 200) {
  pwm01 = p1_y;
}

if(p1_y < 127) {
  pwm01 = 104;
}

if(p1_y < 54) {
  pwm01 = p1_y;
}
__________________
What place are we at? ... TODAI!

Last edited by JohnC : 14-01-2008 at 01:19.
  #5   Spotlight this post!  
Unread 14-01-2008, 00:56
Gamer930's Avatar
Gamer930 Gamer930 is offline
Team 930 and 171 Alumni
AKA: Justin
no team
Team Role: Alumni
 
Join Date: Mar 2002
Rookie Year: 2002
Location: New Berlin, WI
Posts: 388
Gamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to behold
Re: Controller Speed programming

Quote:
Originally Posted by JohnC View Post
This code should work copied and pasted (assuming you want your Port 1 joystick to control pwm01):
Code:
if(p1_y > 127) {
  pwm01 = 150;
}

if(p1_y > 200) {
  pwm01 = p1_y;
}
Just a word of wisdom: If you are doing consecutive if statements comparing the same variable to numbers it is almost always better to use multiple ElseIf.

Why? With If statements the processor has to check each condition to see if it is true or false. In an if/if else statement once condition is true it skips all other. This will allow you programs to execute faster.

Won't notice much of a difference in this programming but if you start getting longer If statements with huge conditions you will start noticing the speed difference
__________________
2010 to Present, Scorekeeper/Field Power Volunteer for FRC/FTC/FLL
2005 - 2010, Team 171 College Mentor
2002 - 2005, Team 930 Student
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
Speed Controller Code ND4SPDLSC Programming 2 18-02-2006 21:48
Speed Controller Data viewtyjoe National Instruments LabVIEW and Data Acquisition 4 02-02-2006 16:05
speed controller max speed Team 668 Programming 15 13-02-2005 14:05
Speed Controller Megas_xlr Control System 3 18-01-2005 15:41
Speed Controller Megas_xlr Electrical 3 18-01-2005 15:41


All times are GMT -5. The time now is 18:34.

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