View Single Post
  #11   Spotlight this post!  
Unread 15-01-2008, 00:21
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,785
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Getting constant motor power with IR board

Quote:
Originally Posted by Nightfall831 View Post
hmmm....i don't quite understand this part
what exactly does this do? especially the first part.
Sorry, it makes more sense in the context of the workshop.
Take a look at this example instead: http://team358.org/files/programming...or_example.zip
It collects the inputs in Process_Data_From_Local_IO() and executes the related commands in Default_Routine().

Here's what the first example is doing...
Code:
sensorReading  = PORTJ>>4;  // Combined digital inputs 15-18
Digital inputs 15,16,17,18 are all just the last 4 bits in a byte named PORTJ, so you can capture all the pin values in one step and avoid the half-and-half state you might get by checking the pins one at a time while the IR sensor is possibly changing states.
Since we only want the last 4 bits of PORTJ, >>4 is used to shift them 4 bits to the right thereby eliminating the other bits in that byte.
So sensorReading now has one of these possible (values)/states for the 4 signal pins from the IR sensor:
(0) 0, 0, 0, 0 - no button
(1) 0, 0, 0, 1 - button 3
(2) 0, 0, 1, 0 - button 2
(4) 0, 1, 0, 0 - button 4
(8) 1, 0, 0, 0 - button 1
This does depends on which signal pin got which wire from the IR sensor.

Code:
  if (latch == 1) 
  {
    if (sensorReading == 0)
    {
      latch = 0; // Take only the 1st reading to avoid being caught by a half & half state of the IR sensor
    }
  }
That section only captures the first reading when the IR sensor sends a command. It latches onto the first value and then doesn't pay any more attention until the IR sensor stops sending the command and all signal inputs = 0 again.

Code:
  else if (sensorReading != 0)
  {
       latch = 1;

       if (sensorReading == 8)      IR_cmd = 1;
       else if (sensorReading == 4) IR_cmd = 4;
       else if (sensorReading == 2) IR_cmd = 2;
       else if (sensorReading == 1) IR_cmd = 3;

        printf("IR_cmd = %d\r\n", IR_cmd);
}
The last part just converts the possible sensorReading values into the command corresponding to the IR wire plugged into that signal pin. It sets the command and then keeps that command until the IR sensor sends another command.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 15-01-2008 at 00:26.