Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumOther questionsOther Wiring questions › Program switch?

Page Index Toggle Pages: 1
Program switch? (Read 7682 times)
08/01/08 at 19:06:08

Titus   Offline
YaBB Moderator
Wiring Soccer Robot!
Amsterdam

Posts: 176
*****
 
As part of our robot competitions( 2 vs 2 soccer) there is a kickoff.
We have seen a lot of robot's starting after a few seconds in stead of responding immediatly.
This is like the 7 second delay with wiring.

Now I thought I solved it, although it wasn't perfect.
What I did was:

I mounted a switch(see diagrams on the example page) on pin 25.
When the switch was "off"  I wanted the program to reset all variables etc once and then wait for the switch to be flipped to "on".
When the switch was flipped to "on", the program started running, and checking if the switch was already flipped to "off".

My code for that was:

Code:
# define SWITCH_PIN 25
# define LED 48//on board led

int setupcounter;
int variable_0=0;
int variable_1=0;

void setup()
{
pinMode(SWITCH_PIN, INPUT);

variable_0=0;
variable_1=0;
setupcounter=1;

Serial.begin(9600);

loop();
}

void loop()
{
  Switch();
  delayMicroseconds(1);
}

void Switch()
{
  if(digitalRead(SWITCH_PIN)==HIGH)//should run the program
  {
    setupcounter=0;
    digitalWrite(LED,LOW);
    Run();
  }
  else
  {
    if (setupcounter==0)//reset!
    {
      setup();
    }
    else//wait for the switch to be flipped "on"
    {
      digitalWrite(LED,HIGH);
      delay(1);
    }
  }
}

void Run()
{
Serial.print("the program is running");
variable_0=253;
variable_1++;

delay(1000);
}

 



This seemed to work quite smooth, until I found out that the delay in void Run() caused the program to finish the delay time, and then the program would notice the switch being flipped to "off".

-Is there a better way to check the Switch's status?

Aswell I was scared about the (micro)delays in void loop() and void Switch()
Deleting them would cause wiring to overload?

Is this a correct and fail proof way to add a program switch to wiring? Or should I make an adjustment to the program.
I''m open for other suggestions on how to do this aswell.

-There is no way for 2 things to be checked simultaniously? like parallel tasks?

Thanks for your help

Titus
(moderator of this forum w00t!)

Edit: 100e post!!!

 

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Reply #1 - 08/05/08 at 15:55:09

Vaccumdiode2   Offline
Full Member
chicago, IL USA

Posts: 120
***
 
Hello Titus,
                 I would check the switch more often, with a simple if/then.

If (Digitalread(SWITCH_PIN) == LOW)
 {
      switch();
 }
          I'm not sure if this will slow you down too much but if you put it before your delay and shorten your delay you could come out alright.

          The other thought I had was to put it on an External Interrupts pin.

 attachInterrupt(0, Switch, LOW); // set Switch to be called everytime
                                 // interrupt 0 is generated (everytime the pin gets LOW

          That may work the best for you.  But, I'm not sure if you are already using all of the Interrupts currently in the rest of your program.

           I hope it helps

Rich  Wink
 
IP Logged
 
Reply #2 - 08/06/08 at 08:25:46

Titus   Offline
YaBB Moderator
Wiring Soccer Robot!
Amsterdam

Posts: 176
*****
 
That's a great idea,

But does the program continue when the pin goes high again, since I want to reset my variables after that?

Titus
 

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Reply #3 - 08/06/08 at 15:07:11

Vaccumdiode2   Offline
Full Member
chicago, IL USA

Posts: 120
***
 
Titus,
          It should.  it calls out your Subroutine "SWITCH" and it should follow the program from there.  I have not tried it but from what I have read it should work that way.  
          Keep me posted on it.  Also what type of communication are you using for your soccer bots?  Zigbee maybe?  

Well have fun!

Rich Wink
 
IP Logged
 
Reply #4 - 08/06/08 at 16:23:14

Titus   Offline
YaBB Moderator
Wiring Soccer Robot!
Amsterdam

Posts: 176
*****
 
Going to dig in that, thanks,

Read the CC2500 topic in tangling computing:P That thing is a nice piece of "art". Though we have no clue how to use it:P

Off topic: Did you read my PM?
 

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Reply #5 - 08/08/08 at 15:29:45

Vaccumdiode2   Offline
Full Member
chicago, IL USA

Posts: 120
***
 
Titus,
              You know the old saying "What goes around comes around!"  Well it hit me in a possitive way.  Help you out gave me a great Idea for my line follower to simplify it.  I can attach an interrupt and then after I turn then I can detach it.  and when the interrupts are not kicking in I can run the bot foreward.  Do you think it will work?  Well I'll Try it and Let you know.  I need to finish the motor /sensor board this weekend and I will try it after I test the board. 

Thank you
Rich
 
IP Logged
 
Reply #6 - 08/08/08 at 16:55:34

Titus   Offline
YaBB Moderator
Wiring Soccer Robot!
Amsterdam

Posts: 176
*****
 
could work, will work it think,
but if you want a smooth line follower, use analog value's. They are accurate. And external interupts are digital.
you could make a comperator circuit to calibrate you "high" value, but I would recommend using analog sensors(like the wiring diagram of the photoresistor(LDR))
 

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Reply #7 - 08/08/08 at 17:20:20

Vaccumdiode2   Offline
Full Member
chicago, IL USA

Posts: 120
***
 
Titus,
           When I get the hard ware together I can try out all kinds of things.  But I think your right about the analog being a smother operation. 
            The way I was going to do the digital interrupt program was use small direction changes and after each change clear the variables and move forward a little.    If I make the program simple enough I was hoping to loop through it at high rate and get my smoth operation that way.  Just sharing my thoughs.  either way it will be great to start play with franken Tank Bot.  I hope to use the same platform for more advance compatitions.

Thank you for the help, encourgement and opinions.

Rich
 
IP Logged
 
Page Index Toggle Pages: 1