Go to Post I got to meet Andy Baker, and Grady, and I saw Andy Brockway. Is that like an Andy Triple Play or something?? ;) - Ian Curtis [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 14-01-2008, 19:12
Nightfall831 Nightfall831 is offline
Registered User
AKA: Paul
FRC #0888 (Robotiators)
Team Role: Alumni
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Maryland
Posts: 29
Nightfall831 will become famous soon enoughNightfall831 will become famous soon enough
Send a message via AIM to Nightfall831
Getting constant motor power with IR board

today i put the ir board on our robot after some preliminary testing and I have managed to get the robot to respond to the IR signals sent to the IR board.

however, the motors only run for as long as the IR board recieves a signal (less than a second)

our current code looks something like
Code:
if (rc_dig_in01)
     {
          pwm03 = pwm04 = 1;
          pwm07 = pwm08 = 255;
     }
i am not surprised at the result i am getting, but all attempts to create constant motion have failed. the only way i can think of is to have the remote cause a variable to be "true" and so that

Code:
while (variable = true)
     {
          pwm03 = pwm04 = 1;
          pwm07 = pwm08 = 255;
     }
or something to that effect

any suggestions?
__________________


That's a PEBKAC problem. (Problem Exists Between Keyboard And Chair)
^Yea, I never run into those...

  #2   Spotlight this post!  
Unread 14-01-2008, 19:25
jratcliff jratcliff is offline
Registered User
no team
 
Join Date: Jan 2008
Location: Lake Saint Louis, Missouri, USA
Posts: 10
jratcliff will become famous soon enoughjratcliff will become famous soon enough
Re: Getting constant motor power with IR board

Quote:
Originally Posted by Nightfall831 View Post
today i put the ir board on our robot after some preliminary testing and I have managed to get the robot to respond to the IR signals sent to the IR board.

however, the motors only run for as long as the IR board recieves a signal (less than a second)

our current code looks something like
Code:
if (rc_dig_in01)
     {
          pwm03 = pwm04 = 1;
          pwm07 = pwm08 = 255;
     }


i am not surprised at the result i am getting, but all attempts to create constant motion have failed. the only way i can think of is to have the remote cause a variable to be "true" and so that

Code:
while (variable = true)
     {
          pwm03 = pwm04 = 1;
          pwm07 = pwm08 = 255;
     }
or something to that effect

any suggestions?
You are on the right track. You should start developing routines that do things like 'go forward' and 'go left'. Next, when you get an IR signal you will set a variable that says which routines to run 'forward', 'left', 'stop' , etc. You will probably not be able to control the robot in real-time with the IR inputs.

Instead think if it as sending 'commands' that you will execute until told otherwise. There is going to be a lot of IR scatter and interference so don't expect to get a low latency response from the controller.

John
  #3   Spotlight this post!  
Unread 14-01-2008, 19:33
Nightfall831 Nightfall831 is offline
Registered User
AKA: Paul
FRC #0888 (Robotiators)
Team Role: Alumni
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Maryland
Posts: 29
Nightfall831 will become famous soon enoughNightfall831 will become famous soon enough
Send a message via AIM to Nightfall831
Re: Getting constant motor power with IR board

yea thats the plan, i just needed it to be doing something by tomorrow because im supposed to be showing it off. :-)

as far as routines go and such, im not really sure how i go about doing that because i really only started programming...uhh...today...i have some basic knowledge in C++ and python, so i know enough to fake as much as i have so far...

thanks.
__________________


That's a PEBKAC problem. (Problem Exists Between Keyboard And Chair)
^Yea, I never run into those...

  #4   Spotlight this post!  
Unread 14-01-2008, 19:43
Ian Curtis Ian Curtis is offline
Best Available Data
FRC #1778 (Chill Out!)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Puget Sound
Posts: 2,520
Ian Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond repute
Re: Getting constant motor power with IR board

Or, even simpler, just put a wait in after you set your pwm's to 255. Make it so your robot goes a reasonable distance (10-15 feet maybe)? That way your motion won't be jerky, and your driver will have some choice in what's going on. Also, if the IR signal goes bad, your robot won't do something silly like ram into a wall, or if you only get one signal through, it'll still move.
__________________
CHILL OUT! | Aero Stability & Control Engineer
Adam Savage's Obsessions (TED Talk) (Part 2)
It is much easier to call someone else a genius than admit to yourself that you are lazy. - Dave Gingery
  #5   Spotlight this post!  
Unread 14-01-2008, 19:49
elvin23's Avatar
elvin23 elvin23 is offline
not cool
FRC #0354 (354)
 
Join Date: Jan 2008
Rookie Year: 2007
Location: . . .
Posts: 41
elvin23 can only hope to improve
Send a message via AIM to elvin23
Thumbs up I LOVE TO MAKE PROGRAMS

i made many programs for fun and none have worked if anyone has programs they want to share just post it
  #6   Spotlight this post!  
Unread 14-01-2008, 23:13
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,712
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

This is a simple example we used in a workshop on Saturday for a full-sized RC. We also have an alternative style we ran on an Edu mini-robot. Everything is self-contained in the Default_Routine().

http://team358.org/files/programming...or_example.zip
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 14-01-2008 at 23:19.
  #7   Spotlight this post!  
Unread 14-01-2008, 23:27
Nightfall831 Nightfall831 is offline
Registered User
AKA: Paul
FRC #0888 (Robotiators)
Team Role: Alumni
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Maryland
Posts: 29
Nightfall831 will become famous soon enoughNightfall831 will become famous soon enough
Send a message via AIM to Nightfall831
Re: Getting constant motor power with IR board

hmmm....i don't quite understand this part

Code:
sensorReading  = PORTJ>>4;  // Combined digital inputs 15-18

  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
    }
  }
  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);
}
what exactly does this do? especially the first part.
__________________


That's a PEBKAC problem. (Problem Exists Between Keyboard And Chair)
^Yea, I never run into those...

  #8   Spotlight this post!  
Unread 14-01-2008, 23:34
Jon Stratis's Avatar
Jon Stratis Jon Stratis is offline
Electrical/Programming Mentor
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Minnesota
Posts: 3,732
Jon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond repute
Re: Getting constant motor power with IR board

One thing that might help you quite a bit would be to lay everything out in a state diagram, or a state machine. Wikipedia does an ok job with the general idea, with a few decent pictures. http://en.wikipedia.org/wiki/State_machine

The basic concept is to draw a bubble to represent discrete thing you want your robot to do during hybrid mode (for example, drive straight, turn to the left, stop). Then you draw arrows between the state and set conditions for those transitions. For example, you might have an arrow to the stop state and trigger that with a "4" signal. Then an arrow from stop to drive forward with a "1" signal. Other cases, you might have it time based - drive forward, and 5 seconds later turn left 180 degrees.

State machines are extremely powerful things, and are especially great for an application like this.
  #9   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,712
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.
  #10   Spotlight this post!  
Unread 15-01-2008, 00:49
taggartbg taggartbg is offline
Registered User
FRC #1712 (Dawgma)
Team Role: Electrical
 
Join Date: May 2005
Rookie Year: 2006
Location: Lower Merion, PA
Posts: 38
taggartbg will become famous soon enoughtaggartbg will become famous soon enough
Send a message via AIM to taggartbg Send a message via MSN to taggartbg Send a message via Yahoo to taggartbg
Re: Getting constant motor power with IR board

To overcome this, I made friendly with Wait().

Another thing i've been considering however, is that if you print the value of GetDigitalInput(x), you get either a 1 or a 0. While the board is receiving a modulated IR signal, you get so many 1's and so many 0's in a row, alternating. Thus I think you can do something like this:

Quote:
int n = 0;
int nmax = number; //This value will be different per controller and button
if (GetDigitalInput(1) = 1)
{
while (n < nmax)
{
SetPWM(1,255);
SetPWM(2,255);
if (GetDigitalInput(1) = 0)
{
n++
}}}
This will keep the PWMs set, as long as the string of 0's (between the 1's) does not exceed a certain number. This number can be determined by adding a simple print and monitoring, and stopping at the right time, your terminal while pressing a button.

I'm not sure how well this would work, maybe something I'll play with tomorrow.
  #11   Spotlight this post!  
Unread 15-01-2008, 09:11
nick1230's Avatar
nick1230 nick1230 is offline
Registered User
FRC #0888
 
Join Date: Dec 2007
Location: Maryland
Posts: 9
nick1230 is an unknown quantity at this point
Re: Getting constant motor power with IR board

thank you all who have helped so far. One more problem though... we have come to the conclusion the one pin #17 on the rc doesn't work. we can wire it all different ways and it is always that pin that doesn't send the signal properly. ITS NOT THE IR BOARD.

the code we're using right now has been copied and modified from Mark McLeod (thank you by the way). We understand the bit shift idea, but since pin 17 doesn't work (don;t worry, its last year's rc), it limits us to 3 commands. can you explain how to bit shift it two more so we're using pins 13-16 instead.
__________________

"Confucius say: He who play in root, eventually kill tree."
  #12   Spotlight this post!  
Unread 15-01-2008, 09:22
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Getting constant motor power with IR board

Quote:
Originally Posted by nick1230 View Post
...pin 17 doesn't work...
Double-check the initialization to make sure digital I/O pin 17 isn't being configured as an output.
  #13   Spotlight this post!  
Unread 14-01-2008, 19:43
nick1230's Avatar
nick1230 nick1230 is offline
Registered User
FRC #0888
 
Join Date: Dec 2007
Location: Maryland
Posts: 9
nick1230 is an unknown quantity at this point
Re: Getting constant motor power with IR board

Quote:
Originally Posted by Nightfall831 View Post
so i know enough to fake as much as i have so far...

yay faking it
__________________

"Confucius say: He who play in root, eventually kill tree."
  #14   Spotlight this post!  
Unread 14-01-2008, 23:59
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Getting constant motor power with IR board

Quote:
Originally Posted by Nightfall831 View Post
...the motors only run for as long as the IR board recieves a signal (less than a second)...all attempts to create constant motion have failed.
The section code you posted looks okay. I suspect something later is resetting your pwms to neutral when no IR signals are being received.
  #15   Spotlight this post!  
Unread 15-01-2008, 08:24
JBotAlan's Avatar
JBotAlan JBotAlan is offline
Forever chasing the 'bot around
AKA: Jacob Rau
FRC #5263
Team Role: Mentor
 
Join Date: Sep 2004
Rookie Year: 2004
Location: Riverview, MI
Posts: 723
JBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond repute
Send a message via AIM to JBotAlan Send a message via Yahoo to JBotAlan
Re: Getting constant motor power with IR board

NOTE: Programmers with more experience than I, feel free to chime in...I've learned that my methods are sometimes not the shortest/best route from A to B...

Also note that the post above mine is in easyC--it looks like you are using MPLAB. That's all right, just as long as you don't try to insert easyC snippets into your MPLAB project.

Quote:
Originally Posted by Nightfall831 View Post
i am not surprised at the result i am getting, but all attempts to create constant motion have failed. the only way i can think of is to have the remote cause a variable to be "true" and so that

Code:
while (variable = true)
     {
          pwm03 = pwm04 = 1;
          pwm07 = pwm08 = 255;
     }
or something to that effect

any suggestions?
That's basically what you want to do; if you want an IR command to send the robot x amount of feet forward, a simple way of doing this would be to define a variable used for time.

Now, if you define said variable inside the function (where you are writing the code snippets you posted), the variable will lose its value every time the function is called. There are two ways to fix this problem. One way (the preferred method, I'd say) is to define the variable as static--instead of
Code:
int variable;
you'd put
Code:
static int variable;
What this does is it makes the variable hold onto its value even when the processor isn't calling the function. Another way to make the variable keep its value is to define it outside of the function. Instead of putting the "int variable;" inside your function, you can put it at the top of the file, where it will hold its value between function calls. Note that this method should only really be used if more than one function need access to this variable; otherwise the first method I mentioned provides better readability.

Once you have the variable defined, one way of doing what you desire is to use that variable as a countdown to when the robot is going to stop. That way, when you recieve an IR signal, you can set it to a value that means "1 second" (will not be 1--let me explain in a moment), and each loop, the robot will subtract 1 from that value. Once the counter reaches 0, it will shut off the motors and stop subtracting.

Realize that if you write this code inside of Process_Data_From_Master_uP (sorry if I have the function name wrong...I don't have MPLAB in front of me right now) or it calls the function that executes this code, it will run about every 23 milliseconds--a millisecond is a thousandth of a second. Using that bit of information, you can calculate how big your counter should be: 5 seconds = 5000 milliseconds / 23 milliseconds per tick = 217 ticks.

I would post some sample code, but I'd like to see you try to write it first--I want you to know this inside-and-out before the first regional.

Let me know if you need more help.
JBot
__________________
Aren't signatures a bit outdated?
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
Issues with non working victor constant orange led dani190 Control System 10 21-12-2007 22:32
Denso window motor, getting spares caffel Motors 4 09-02-2006 11:47
cim motor power question Zippiot Motors 16 16-02-2005 20:40
Getting the relays to stay constant Lord Nerdlinger Programming 2 19-02-2004 10:17
power of globe motor with gear box? Ken Leung Motors 5 21-11-2001 13:43


All times are GMT -5. The time now is 16:10.

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