Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Controller Speed programming (http://www.chiefdelphi.com/forums/showthread.php?t=61610)

team877 13-01-2008 19:51

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

tseres 13-01-2008 20:02

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 ;)

Gamer930 13-01-2008 20:02

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

JohnC 14-01-2008 00:35

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;
}


Gamer930 14-01-2008 00:56

Re: Controller Speed programming
 
Quote:

Originally Posted by JohnC (Post 677379)
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


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

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi