Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Automatic counter-Encoder (http://www.chiefdelphi.com/forums/showthread.php?t=67444)

Generalx5 04-05-2008 00:44

Re: Automatic counter-Encoder
 
So it was all in the programming. I dont know how it happened, but I think there is a conflict with my codes. At the very bottom of the code, I have an else statment, and under tthat all the pwms would become 127, all the relays, solenoids would become off. But when I changed that to all being on.

and loaded the program into the RC. I got tthis super fast clicking response. all my relays were firing like a buzzer and so were the solenoids!!! freeky!!

I think the problem is from all my if's ....

if ....
{
blah blah blah
}
if.....
{
robot is hungry: Go to macD's
}
if.....
{
The rise of machines, assimilation !=1
}
else
{
shut down everything
}



Thats pretty much what my code looks like.....
if.....

Mark McLeod 04-05-2008 09:05

Re: Automatic counter-Encoder
 
You need to walk through your code step-by-step and make a logic table of what the code will do at each step. It sounds as if your logic is doing one of your "if"'s when it goes through your statements, then the very next time through it's deciding to do something different.
You'll get a pulsing as fast as your code changes it's mind. On the EDU this loop of your's can change it's mind 59 times a second in user_routines.c.

Quote:

Originally Posted by Generalx5 (Post 745452)
I think the problem is from all my if's ....

if ....
{
blah blah blah
}
if.....
{
robot is hungry: Go to macD's
}
if.....
{
The rise of machines, assimilation !=1
}
else
{
shut down everything
}

"If" the contents of each of your if statements is supposed to be mutually exclusive, then you should probably be using "else if" statements instead. That just keeps them from trying to do three different actions at the same time. The last if will win.

For example:
Code:

if ....
{
    blah blah blah
}
else if.....
{
    robot is hungry: Go to macD's
}
else
{
    shut down everything
}


Generalx5 06-05-2008 00:03

Re: Automatic counter-Encoder
 
would it still be correct if I did it in this way:

if.....

else if.....

else if.....

else if.....


else......

Are there any limits on how many else if's I can use?

Mark McLeod 06-05-2008 10:12

Re: Automatic counter-Encoder
 
That's correct.

There isn't a limit on how many you string together.
After a couple of pages it will become unreadable though...

Kevin Sevcik 06-05-2008 10:40

Re: Automatic counter-Encoder
 
Quote:

Originally Posted by Generalx5 (Post 746026)
Are there any limits on how many else if's I can use?

Quote:

Originally Posted by Mark McLeod (Post 746100)
That's correct.

There isn't a limit on how many you string together.
After a couple of pages it will become unreadable though...

Read Mark's answer as:
After a couple of pages, you might want to figure out how to do this with a switch-case structure or something else.

Switch-case structures are especially nice for implementing a state machine to simplify things like this. Assuming you're using this to make certain moves at certain distances traveled, you can make all the moves relative to the last one. So if you discover you need to travel 5 more inches halfway through your 20 step sequence, you only have to change 1 number, not 10.

Generalx5 07-05-2008 16:53

Re: Automatic counter-Encoder
 
Sounds good! Thanks for all the help :p


All times are GMT -5. The time now is 20:26.

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