Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Relay program? (http://www.chiefdelphi.com/forums/showthread.php?t=62795)

team877 29-01-2008 16:22

Relay program?
 
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

Re: Relay program?
 
Comparisons don't "chain" like that in C. Do it this way:
Code:

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

Re: Relay program?
 
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

Re: Relay program?
 
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

Re: Relay program?
 
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

Re: Relay program?
 
1 Attachment(s)
here is our code you asked for....

paulcd2000 02-02-2008 12:39

Re: Relay program?
 
where are you setting the value of x?

xrabohrok 02-02-2008 13:26

Re: Relay program?
 
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

Re: Relay program?
 
Quote:

Originally Posted by team877 (Post 690675)
here is our code you asked for....
Code:

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

Re: Relay program?
 
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

Re: Relay program?
 
Quote:

Originally Posted by team877 (Post 691812)
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

Re: Relay program?
 
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()


All times are GMT -5. The time now is 08:44.

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