Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   quick question: TIMERS (http://www.chiefdelphi.com/forums/showthread.php?t=26637)

Astronouth7303 16-03-2004 13:49

Re: quick question: TIMERS
 
Huh? You are talking about the IO on the RC, right? In auto mode, the OI transmits inputs as neutural.

Xufer 16-03-2004 14:48

Re: quick question: TIMERS
 
so it would be like:

#define digin10old

then later on ....

digin10old = (rc_dig_in10)
putdata()

Alan Anderson 16-03-2004 16:10

Re: quick question: TIMERS
 
Quote:

Originally Posted by Xufer
so it would be like:

#define digin10old

then later on ....

digin10old = (rc_dig_in10)
putdata()

No, it would not be like that, for a whole bunch of reasons.

Contrary to an earlier post, the RC inputs such as rc_dig_in10 do work during autonomous mode, so there's no reason to do it this way. The advice to save the values for later use applies only to OI inputs (knobs and switches, mostly) that you want to use to configure autonomous operation.

Also, variables in c aren't declared using #define statements. The proper syntax is not trivial, but it is not important here, since you don't need to use a variable for this purpose.

Xufer 16-03-2004 17:56

Re: quick question: TIMERS
 
so it would be done how then ?

Alan Anderson 16-03-2004 19:02

Re: quick question: TIMERS
 
Quote:

Originally Posted by Xufer
so it would be done how then ?

It would be done the way Mark McLeod explained back in response #42, testing the digital input with a simple if statement.

Xufer 17-03-2004 13:20

Re: quick question: TIMERS
 
Code:

if (rc_dig_in18=1)        {

                        if (cnttick < 34 )
                        {
                                pwm05 = 60;
                                  }
                        if (cnttick > 35 )
                        {
                                pwm05 = 127;
                                  }
                        if (cnttick < 30 )
                        {
                                pwm04 = 0;
                                  }
                        if (cnttick < 32 )
                        {
                                pwm04 = 127;
                                  }
//raises arm up for 40 ticks 1 second(s) /\ /\

// drive motors from here on out \/  \/
                       
                        if (cnttick > 35 && cnttick < 90 )
                        {
                                pwm01 = 190;
                                  }

                        if (cnttick > 35 && cnttick < 90 )
                        {
                                pwm02 = 190;
                                  }
                        if (cnttick > 92  && cnttick <= 122)
                        {
                                pwm01 = 190;
                        }

                        if (cnttick > 92 && cnttick <= 122)
                        {
                                pwm02 = 53;
                        }
                        if (cnttick > 130 && cnttick < 160 )
                        {
                                pwm01 = 190;
                                  }

                        if (cnttick > 130 &&  cnttick < 160)
                        {
                                pwm02 = 190;
                          }
                        if (cnttick > 163  && cnttick <= 183)
                        {
                                pwm01 = 190;
                        }

                        if (cnttick > 163 && cnttick <= 183)
                        {
                                pwm02 = 53;
                        }
                        if (cnttick > 223 && cnttick < 250 )
                        {
                                pwm01 = 190;
                                  }

                        if (cnttick > 223 && cnttick < 250 )
                        {
                                pwm02 = 190;
                          }
                        if (cnttick > 255  && cnttick <= 275)
                        {
                                pwm01 = 190;
                        }

                        if (cnttick > 255 && cnttick <= 275)
                        {
                                pwm02 = 53;
                        }

}

else {
                        pwm01=210;
}

when i do it like that reguardless of the switch it always works like the switch is on even when its off.

10intheCrunch 17-03-2004 13:29

Re: quick question: TIMERS
 
Quote:

Contrary to an earlier post, the RC inputs such as rc_dig_in10 do work during autonomous mode, so there's no reason to do it this way. The advice to save the values for later use applies only to OI inputs (knobs and switches, mostly) that you want to use to configure autonomous operation.
My mistake. Sorry to confuse...

Your code seems ok at first glance...why don't you put this statement in your Process_data function:

printf("%d\n", (int)rc_dig_in18);

Check the console printout while your program cable is plugged in. Make sure that it changes properly with the switch on your robot.

Too improve efficiency: use else if statements. For example:

if(ticks < 15)
blah;
else if (ticks < 35)
blah;

That will handle your decisions faster...

Sorry again if I confused you eariler. :)

Xufer 17-03-2004 13:36

Re: quick question: TIMERS
 
Quote:

Originally Posted by 10intheCrunch
My mistake. Sorry to confuse...

Your code seems ok at first glance...why don't you put this statement in your Process_data function:

printf("%d\n", (int)rc_dig_in18);

Check the console printout while your program cable is plugged in. Make sure that it changes properly with the switch on your robot.

Too improve efficiency: use else if statements. For example:

if(ticks < 15)
blah;
else if (ticks < 35)
blah;

That will handle your decisions faster...

Sorry again if I confused you eariler. :)

i stuck in the printf statement and it shows the switch on and off depending on the position, so i know its not the switch its something i did.

pink967 17-03-2004 13:50

Re: quick question: TIMERS
 
you guys are all really smart...i need to learn this stuff, or else i don't get to be on my team next year

Alan Anderson 17-03-2004 14:07

Re: quick question: TIMERS
 
Quote:

Originally Posted by Xufer
Code:

if (rc_dig_in18=1)        {
when i do it like that reguardless of the switch it always works like the switch is on even when its off.

That's because you've fallen into a common trap with the c language's syntax. Testing for equality is done with the == "is equal" operator, and you've instead used the = "assignment" operator. Your code assigns the value "1" to the variable "rc_dig_in18", and then tests the result -- which is always 1, interpreted as true by the software.

What your first line should say instead is this:
Code:

if (rc_dig_in18==1)        {
Or you could leave off the explicit test for 1, and let c's boolean rules work for you:
Code:

if (rc_dig_in18)        {
That should take care of the problem you're having.

Xufer 17-03-2004 21:37

Re: quick question: TIMERS
 
Quote:

Originally Posted by Alan Anderson
That's because you've fallen into a common trap with the c language's syntax. Testing for equality is done with the == "is equal" operator, and you've instead used the = "assignment" operator. Your code assigns the value "1" to the variable "rc_dig_in18", and then tests the result -- which is always 1, interpreted as true by the software.

What your first line should say instead is this:
Code:

if (rc_dig_in18==1)        {
Or you could leave off the explicit test for 1, and let c's boolean rules work for you:
Code:

if (rc_dig_in18)        {
That should take care of the problem you're having.

mmk thnx, but j/w how would i do it if i was to have like 4 auton modes i have a sitch box that will occupy 6 dig_in's

Astronouth7303 18-03-2004 07:28

Re: quick question: TIMERS
 
Quote:

Originally Posted by Xufer
mmk thnx, but j/w how would i do it if i was to have like 4 auton modes i have a sitch box that will occupy 6 dig_in's

Four modes and six dig ins? To do four modes, you only need 2! With 6, you can have 64 modes!

Alan Anderson 18-03-2004 08:42

Re: quick question: TIMERS
 
Quote:

Originally Posted by Xufer
...how would i do it if i was to have like 4 auton modes...

You have a couple of options. Simplest in your case would probably be to do something like this:
Code:

// somehow get a number in the "auto" variable
  auto = (rc_dig_in18<<2) | (rc_dig_in17<<1) | (rc_dig_in16);
// or whatever it takes to turn your switches into a value
  if (auto==1)
  {
    // code for mode 1
  }
  if (auto==2)
  {
    // code for mode 2
  }
  // etc.

It might theoretically be more efficient to use a switch/case statement instead of a string of ifs, but you probably have enough to focus on right now without worrying about learning another control structure.

Ryan M. 18-03-2004 08:49

Re: quick question: TIMERS
 
Quote:

Originally Posted by Astronouth7303
Four modes and six dig ins? To do four modes, you only need 2! With 6, you can have 64 modes!

Just to show what he means:
Code:

      On  Off
sw1  1      2
sw2  3      4

Where sw1 and sw2 are the two switches and the numbers in the center are the automous modes.


All times are GMT -5. The time now is 12:47.

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