Log in

View Full Version : Relay program?


team877
29-01-2008, 16:22
I need help trying to figure out a program. I want to engage a relay when my right and left drive motors are between 125 and 129. I thought it would be something along the lines of 125 < x < 129 but i cant seem to get this to function can anyone help me out?

Alan Anderson
29-01-2008, 16:31
Comparisons don't "chain" like that in C. Do it this way:

if ( (125 < x) && (x < 129) )

The inner parentheses aren't strictly necessary, but I think they make it much more readable.

Code Monkey
29-01-2008, 16:40
do a printf of x. You may not be getting the PWM value you think you are.
We have had problems with pwmXX values not being available in all of our subroutines. If that is working, try a nested if-not as elegant, but it works.
Lastly try increasing the band you are allowing on 127-your offset may be off or you go through it too fast.

Check that your value to the relay routine call is a logical 0 or 1 (try forcing it)

team877
30-01-2008, 19:40
i was thinking i needed to set my x value to say (pwm 1) if i wanted it to work with my pwm. But i tried using pwm control with the x variable inside it and it just makes my pwm continually run is there something i'm missing

Alan Anderson
30-01-2008, 22:40
Show us the code you're trying to make work. Tell us exactly what you want it to do, and we can tell you what to change to make it do that.

team877
02-02-2008, 12:03
here is our code you asked for....

paulcd2000
02-02-2008, 12:39
where are you setting the value of x?

xrabohrok
02-02-2008, 13:26
Where is this file in the overall scheme of the robot? I don't know how to look at easy C to intuitively know what is going on, but it could be you are calling the function in the wrong place. Is the function called in user_routines.c? It should probably called somewhere from within Default_Routines(). I am assuming the easy C version of the code is organized the same way as just regular code.

Alan Anderson
02-02-2008, 20:13
here is our code you asked for....
void operatorControl ( void )
{
unsigned char x;

while ( 1 )
{
SetPwm ( 2 , x ) ; // We’re setting are variable to the motor we want it to measure
if ( 125 < x && x < 129 )
{ // We want this relay to engage between these speeds
SetRelay ( 1 , 1 , 0 ) ;
}
else
{ // And if not turn the relay off
SetRelay ( 1 , 0 , 0 ) ;
}
}
}

I don't see anything that sets the value of x. Did you forget the line that reads the joystick value?

(Is there a reason you posted it as a Word document containing a picture, instead of just copying the text? I don't use Word, and it was inconvenient to convert your file to a readable form.)

team877
04-02-2008, 00:53
the Setpwm (1, x) is a window that you put your variable in so "x" is set to the value of pwm 1

Alan Anderson
04-02-2008, 07:10
the Setpwm (1, x) is a window that you put your variable in so "x" is set to the value of pwm 1

Isn't it the other way around? As an output function, SetPwm( 1, x ) sets pwm 1 to the value of x. I'm not aware of a built-in way to read the present value of a pwm output using easyC.

So where in your program do you actually control the pwm output that you want to use as the trigger for your relay?

Mark McLeod
04-02-2008, 11:11
Normal operation would be to:

1) Get the desired drive value from the driver--GetOIAInput()

2) Do your tests on when you want your relay to be active--if () else

3) Output your relay command--SetRelay()

4) Set your PWM Output--SetPWM()