Go to Post Invest our time in enhancing the process of conceiving, designing, testing and deploying the game - billylo [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 08-02-2006, 00:26
NextPerception NextPerception is offline
Sleep-Deprived
AKA: Matt
FRC #0437 (Richardson Robotics)
Team Role: Mentor
 
Join Date: Sep 2004
Rookie Year: 2005
Location: Richardson, TX
Posts: 69
NextPerception has a spectacular aura aboutNextPerception has a spectacular aura aboutNextPerception has a spectacular aura about
Send a message via AIM to NextPerception
Will camera keep running if i have a while statement going

I have a while statement in Default_Routine that starts when a button is pressed, keeps moving the drive motors until the target is strait ahead of the robot (the pan servo = 127), and then leaves the while loop.
Now here is my question...
during the while loop will the camera keep tracking the target because it is interupt driven or will the while loop overide the camera's tracking interupts and just get me stuck in the loop because the camera wont update.

i am trying to have my robot aim with it's drive wheels when i press a button
__________________
What is this S - L - E - E - P you speak of?
Battlebots - My Robotics Website

  #2   Spotlight this post!  
Unread 08-02-2006, 00:32
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: Will camera keep running if i have a while statement going

you cannot use while or for loops in the RC code.

The main loop of the code does something like this:

1. read all the sensor and OI inputs (including the camera)
2. execute all your code
3. update all the output (to the motors and servos...)
goto 1

as you can see, a while loop in step 2 will hold up the entire program, and stop any further inputs or outputs

to make matters worse, there is another processor in the RC that you do not have access to. If it sees the code is not updating the outputs at the normal rate it assumes your code has gone out to lunch, and it shuts the robot down.

you need to use IF statements to check and see if the condition you are looking for is true. If not then let the code continue, and it will check again on its next loop through.
  #3   Spotlight this post!  
Unread 08-02-2006, 00:40
steven114 steven114 is offline
Programming Wizard and Team Captain
AKA: Steven Schlansker
FRC #0114 (Eaglestrike)
Team Role: Programmer
 
Join Date: Feb 2004
Location: Los Altos, CA
Posts: 335
steven114 is a jewel in the roughsteven114 is a jewel in the roughsteven114 is a jewel in the rough
Send a message via AIM to steven114
Re: Will camera keep running if i have a while statement going

Well, you can use while or for loops - looping over an array is a good use, for example.
__________________
Shift to the left, shift to the right!
Pop up, push down, byte, byte, byte!
  #4   Spotlight this post!  
Unread 08-02-2006, 00:43
NextPerception NextPerception is offline
Sleep-Deprived
AKA: Matt
FRC #0437 (Richardson Robotics)
Team Role: Mentor
 
Join Date: Sep 2004
Rookie Year: 2005
Location: Richardson, TX
Posts: 69
NextPerception has a spectacular aura aboutNextPerception has a spectacular aura aboutNextPerception has a spectacular aura about
Send a message via AIM to NextPerception
Re: Will camera keep running if i have a while statement going

i am just going to post what i have mabye someone can tell me haow i would do this without stopping my entire program. This is my first year programming for first and i have promised my team some nice "features". any help would be greatly appreciated
Code:
  if (p1_sw_trig == 1)
  {  
    Switch1_LED = 1        // aiming light turns on when aiming
    locked = 0
	while (locked == 0)
    {
      if (PAN_SERVO > PAN_CENTER_PWM_DEFAULT + 20)
      {
         pwm01 = 127 + aim_gain
         pwm02 = 127 + aim_gain
      } 
      else if (PAN_SERVO < PAN_CENTER_PWM_DEFAULT - 20)
      {
         pwm01 = 127 - aim_gain
         pwm02 = 127 - aim_gain
      } 
	  else if (PAN_SERVO < PAN_CENTER_PWM_DEFAULT + 21 & PAN_SERVO > PAN_CENTER_PWM_DEFAULT)
      {
        pwm01 = 127 + aim_soft_gain
        pwm02 = 127 + aim_soft_gain
      } 
	  else if (PAN_SERVO > PAN_CENTER_PWM_DEFAULT - 21 & PAN_SERVO < PAN_CENTER_PWM_DEFAULT)
      {
        pwm01 = 127 - aim_soft_gain
        pwm02 = 127 - aim_soft_gain
      } 
      else 
      {
        Switch1_LED = 0  // really cool light scrolling that i had to put somewhere in the code
        Switch2_LED = 0
        Switch3_LED = 0
        Switch1_LED = 1
        Switch1_LED = 0
        Switch2_LED = 1
        Switch2_LED = 0
        Switch3_LED = 1
        Switch3_LED = 0
        Switch2_LED = 1
        Switch2_LED = 0
        Switch1_LED = 1
        Switch1_LED = 0
		printf("\TARGET ACQUIRED");
        locked = 1
      }
    }
  }
__________________
What is this S - L - E - E - P you speak of?
Battlebots - My Robotics Website

  #5   Spotlight this post!  
Unread 08-02-2006, 00:44
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: Will camera keep running if i have a while statement going

yes, if you have a while loop that executes quickly, and that is not looking for a change in inputs, esp if its trying to change the outputs (motor speed) to make the inputs change.

using while loops to process data will also have the adverse effect of altering your code-loop time.
  #6   Spotlight this post!  
Unread 08-02-2006, 00:48
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: Will camera keep running if i have a while statement going

whats going to happen with your code, as soon as

WHILE locked = 0

becomes true, your while loop becomes an infinite loop - it never exits, so your code will never see new input values from the operator interface - it will act like the trigger never gets released

but the supervisor uC will shut the robot down within a second or two anyway, and your bot will act like its been disabled.

Also: your light scrolling- the code needs to flow though to the end before any outputs get updated, so the only output that would happen would be the last values you assign to each output variable.

Last edited by KenWittlief : 08-02-2006 at 00:51.
  #7   Spotlight this post!  
Unread 08-02-2006, 01:02
NextPerception NextPerception is offline
Sleep-Deprived
AKA: Matt
FRC #0437 (Richardson Robotics)
Team Role: Mentor
 
Join Date: Sep 2004
Rookie Year: 2005
Location: Richardson, TX
Posts: 69
NextPerception has a spectacular aura aboutNextPerception has a spectacular aura aboutNextPerception has a spectacular aura about
Send a message via AIM to NextPerception
Re: Will camera keep running if i have a while statement going

wouldn't the last line in the final else statement break it out of the loop once it centers on the traget (the locked = 1). of course then i would still have the "Supervisor Uc" thing yall keep talking about to worry about so i guess it wouldn't work anyway....(not too mention the camera wont work in the loop Sorry for my confusion. I have programmed in a lot of other langauges besides C . I am just new to C and still trying to understand some of the stuff.


What if i put this code into the beginning of the while loop
Code:
Getdata(&rxdata);
Tracking_Info_Terminal();
Camera_Handler();
Servo_Track();
Putdata(&txdata);
also if i add a counter to 1000 and when it reached it it would run the program once but before it did it set a variable that had an if statement near the beginning of the run (but after "Supervisor Uc" checked) that put it back into the while loop. I hope i am not being to vague

it would almost be like making a super high priority interupt
__________________
What is this S - L - E - E - P you speak of?
Battlebots - My Robotics Website

  #8   Spotlight this post!  
Unread 08-02-2006, 01:42
Keith Watson Keith Watson is offline
Registered User
FRC #0957 (WATSON)
Team Role: Mentor
 
Join Date: Feb 2006
Rookie Year: 2006
Location: Wilsonville, OR
Posts: 112
Keith Watson is just really niceKeith Watson is just really niceKeith Watson is just really niceKeith Watson is just really nice
Re: Will camera keep running if i have a while statement going

Remove your while statement. Why? Because your code is already running inside of a while loop.

The loop your code runs inside of runs at 26.2ms per loop.

Setting pwms and LEDs does not immediately change the actual hardware. That occurs later in the loop by the default code after your code is left. So making your light scrolling work needs delays between setting successive lights.

It's not really a C question, it's about how the default code is set up (that you don't normally see).
__________________
Keith Watson - Professional Software Engineer
No relation to "Kevin" Watson, who created the camera tracking code.
  #9   Spotlight this post!  
Unread 08-02-2006, 01:54
NextPerception NextPerception is offline
Sleep-Deprived
AKA: Matt
FRC #0437 (Richardson Robotics)
Team Role: Mentor
 
Join Date: Sep 2004
Rookie Year: 2005
Location: Richardson, TX
Posts: 69
NextPerception has a spectacular aura aboutNextPerception has a spectacular aura aboutNextPerception has a spectacular aura about
Send a message via AIM to NextPerception
Re: Will camera keep running if i have a while statement going

so how would i do this without a while loop???
I understand what you are saying now...
i just dont understand how i can fix it.
if anyone could point me in the right direction or mabye even give me a little default code it would be greatly appreciated. I just dont understand how it would keep the tracking proccess going in the next loop of the "master while statement" but not have it happen every loop. I need it to only hapeen after the trigger is pressed and keep tracking till it is locked on
__________________
What is this S - L - E - E - P you speak of?
Battlebots - My Robotics Website

  #10   Spotlight this post!  
Unread 08-02-2006, 02:03
Keith Watson Keith Watson is offline
Registered User
FRC #0957 (WATSON)
Team Role: Mentor
 
Join Date: Feb 2006
Rookie Year: 2006
Location: Wilsonville, OR
Posts: 112
Keith Watson is just really niceKeith Watson is just really niceKeith Watson is just really niceKeith Watson is just really nice
Re: Will camera keep running if i have a while statement going

Servo_track() is the function which does the camera tracking. In your section of code you can set a global variable to turn camera tracking on/off. Then either add checking that variable before the call to Servo_Track() or add the check inside of Servo_Track() itself.
__________________
Keith Watson - Professional Software Engineer
No relation to "Kevin" Watson, who created the camera tracking code.
  #11   Spotlight this post!  
Unread 08-02-2006, 11:13
DanDon's Avatar
DanDon DanDon is offline
ohhh MY god
AKA: Dan Hoizner
FRC #0375 (The Robotic Plague)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Staten Island, NY
Posts: 1,432
DanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond repute
Send a message via ICQ to DanDon Send a message via AIM to DanDon Send a message via MSN to DanDon
Re: Will camera keep running if i have a while statement going

Quote:
Originally Posted by NextPerception
i am just going to post what i have mabye someone can tell me haow i would do this without stopping my entire program. This is my first year programming for first and i have promised my team some nice "features". any help would be greatly appreciated
Code:
 
if (p1_sw_trig == 1)
{ 
Switch1_LED = 1 // aiming light turns on when aiming
locked = 0
	while (locked == 0)
{
if (PAN_SERVO > PAN_CENTER_PWM_DEFAULT + 20)
{
pwm01 = 127 + aim_gain
pwm02 = 127 + aim_gain
} 
else if (PAN_SERVO < PAN_CENTER_PWM_DEFAULT - 20)
{
pwm01 = 127 - aim_gain
pwm02 = 127 - aim_gain
} 
	 else if (PAN_SERVO < PAN_CENTER_PWM_DEFAULT + 21 & PAN_SERVO > PAN_CENTER_PWM_DEFAULT)
{
pwm01 = 127 + aim_soft_gain
pwm02 = 127 + aim_soft_gain
} 
	 else if (PAN_SERVO > PAN_CENTER_PWM_DEFAULT - 21 & PAN_SERVO < PAN_CENTER_PWM_DEFAULT)
{
pwm01 = 127 - aim_soft_gain
pwm02 = 127 - aim_soft_gain
} 
else 
{
Switch1_LED = 0 // really cool light scrolling that i had to put somewhere in the code
Switch2_LED = 0
Switch3_LED = 0
Switch1_LED = 1
Switch1_LED = 0
Switch2_LED = 1
Switch2_LED = 0
Switch3_LED = 1
Switch3_LED = 0
Switch2_LED = 1
Switch2_LED = 0
Switch1_LED = 1
Switch1_LED = 0
		printf("\TARGET ACQUIRED");
locked = 1
}
}
}
How about instead of putting the if statements inside a while(locked==0), put them inside a giant if(locked==0)?
__________________
  #12   Spotlight this post!  
Unread 08-02-2006, 11:39
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Re: Will camera keep running if i have a while statement going

I think you should be able to make your "locked" variable a static and change your "while" to an "if". As long as the trigger is being held, this code will be executed every time through the main loop. (I think this is approximately what DHoizner was suggesting.)
Code:
static int locked = 0;
static int prev_trig = 0;

  if (p1_sw_trig == 1)
  {  
    if (prev_trig == 0) locked = 0; // Clear flag if trigger just pulled.

    Switch1_LED = 1        // aiming light turns on when aiming
    if (locked == 0)
    {
      if (PAN_SERVO > PAN_CENTER_PWM_DEFAULT + 20)
      {
         pwm01 = 127 + aim_gain
         pwm02 = 127 + aim_gain
      } 
      else if (PAN_SERVO < PAN_CENTER_PWM_DEFAULT - 20)
      {
         pwm01 = 127 - aim_gain
         pwm02 = 127 - aim_gain
      } 
	  else if (PAN_SERVO < PAN_CENTER_PWM_DEFAULT + 21 & PAN_SERVO > PAN_CENTER_PWM_DEFAULT)
      {
        pwm01 = 127 + aim_soft_gain
        pwm02 = 127 + aim_soft_gain
      } 
	  else if (PAN_SERVO > PAN_CENTER_PWM_DEFAULT - 21 & PAN_SERVO < PAN_CENTER_PWM_DEFAULT)
      {
        pwm01 = 127 - aim_soft_gain
        pwm02 = 127 - aim_soft_gain
      } 
      else 
      {
        Switch1_LED = 0  // really cool light scrolling that i had to put somewhere in the code
        Switch2_LED = 0
        Switch3_LED = 0
        Switch1_LED = 1
        Switch1_LED = 0
        Switch2_LED = 1
        Switch2_LED = 0
        Switch3_LED = 1
        Switch3_LED = 0
        Switch2_LED = 1
        Switch2_LED = 0
        Switch1_LED = 1
        Switch1_LED = 0
		printf("TARGET ACQUIRED");
        locked = 1
      }
    }
  }
  prev_trig = p1_sw_trig;
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me

Last edited by Greg Ross : 08-02-2006 at 13:30. Reason: Moved "prev_trig = p1_sw_trig;" outside of "if (p1_sw_trig == 1)"
  #13   Spotlight this post!  
Unread 08-02-2006, 13:04
Keith Watson Keith Watson is offline
Registered User
FRC #0957 (WATSON)
Team Role: Mentor
 
Join Date: Feb 2006
Rookie Year: 2006
Location: Wilsonville, OR
Posts: 112
Keith Watson is just really niceKeith Watson is just really niceKeith Watson is just really niceKeith Watson is just really nice
Re: Will camera keep running if i have a while statement going

Oops, Dan and Greg are right. I stand corrected.
__________________
Keith Watson - Professional Software Engineer
No relation to "Kevin" Watson, who created the camera tracking code.
  #14   Spotlight this post!  
Unread 08-02-2006, 21:53
NextPerception NextPerception is offline
Sleep-Deprived
AKA: Matt
FRC #0437 (Richardson Robotics)
Team Role: Mentor
 
Join Date: Sep 2004
Rookie Year: 2005
Location: Richardson, TX
Posts: 69
NextPerception has a spectacular aura aboutNextPerception has a spectacular aura aboutNextPerception has a spectacular aura about
Send a message via AIM to NextPerception
Re: Will camera keep running if i have a while statement going

thanks to all the people who helped explain this too me. Yall have no idea how much this helped me. Everything just clicked in my head. I get it now. thanks again.
__________________
What is this S - L - E - E - P you speak of?
Battlebots - My Robotics Website

Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CMU Camera kills robot controller if not found. Chris_Elston Programming 21 27-03-2006 14:30
How To Use the Google Camera generalbrando Kit & Additional Hardware 2 07-02-2006 16:00
Camera Is Spazzing Out! BrittanyV Programming 15 04-02-2006 13:39
Moving robot while tracking with camera questions... Steve Orr Programming 6 02-02-2006 22:24
Scripting Setup and the Camera + Serial Port Drivers CJO Programming 22 11-01-2006 17:42


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

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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