|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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;
}
Code:
while (variable = true)
{
pwm03 = pwm04 = 1;
pwm07 = pwm08 = 255;
}
any suggestions? |
|
#2
|
|||
|
|||
|
Re: Getting constant motor power with IR board
Quote:
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
|
|||
|
|||
|
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. |
|
#4
|
||||
|
||||
|
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.
|
|
#5
|
||||
|
||||
|
Re: Getting constant motor power with IR board
yay faking it ![]() |
|
#6
|
||||
|
||||
|
i made many programs for fun and none have worked if anyone has programs they want to share just post it
![]() |
|
#7
|
|||||
|
|||||
|
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 Last edited by Mark McLeod : 14-01-2008 at 23:19. |
|
#8
|
|||
|
|||
|
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);
}
|
|
#9
|
||||
|
||||
|
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. |
|
#10
|
|||||
|
|||||
|
Re: Getting constant motor power with IR board
The section code you posted looks okay. I suspect something later is resetting your pwms to neutral when no IR signals are being received.
|
|
#11
|
|||||
|
|||||
|
Re: Getting constant motor power with IR board
Quote:
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 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
}
}
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);
}
Last edited by Mark McLeod : 15-01-2008 at 00:26. |
|
#12
|
|||
|
|||
|
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:
I'm not sure how well this would work, maybe something I'll play with tomorrow. |
|
#13
|
|||||
|
|||||
|
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:
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; Code:
static int variable; 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 |
|
#14
|
||||
|
||||
|
Re: Getting constant motor power with IR board
Check your remote to see if it's the repeating type. That means when you hold down a button on the remote, the output on the IR board will pulse every 100ms until you release the button.
If that's not the case, I'd highly recommend finding a remote that does this. The first Sony remote we picked up worked nicely for us in this manner. The code below hasn't been tested or compiled since we've just been "pulsing" our motors, and our chassis isn't ready to go full-speed yet. The code below should sets a timer to run the motors for 150ms after it receives a pulse from the IR board. If you have a signal pulsing every 100ms, that means that the timer will keep resetting before it ever expires = constant power. Your robot WILL continue to run for 150ms after you've released the button on the remote, but I'll leave it up to you whether you feel that is acceptable. -Shawn T. Lim... Code:
// set your timer's limit
// see JBot's post, 7 ticks is a little more than 150ms
static char variable = 8;
// ...other code goes here...
// whenever you receive a signal from your IR board, reset your timer
if (rc_dig_in01)
{
variable = 0;
}
// whenever there is no signal, run your timer until it expires
else
{
if (variable < 8)
{
variable++;
}
}
// run your motors if the timer is running
if (variable < 8)
{
pwm03 = pwm04 = 1;
pwm07 = pwm08 = 255;
}
else
// stop motors when timer expires
{
pwm03 = pwm04 = 128;
pwm07 = pwm08 = 128;
}
Last edited by Mr. Lim : 15-01-2008 at 08:51. |
|
#15
|
||||
|
||||
|
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. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |