![]() |
Arduino Mecanum drive using PWM?
I have been trying to program an Arduino Uno to take PWM signals from a spectrum RC receiver and mix those signals to control 4 motors on a mecanum drive bot. Although I don't have the bot built/designed yet I have been trying to get some of the code working. My issue is that when ever I try to use more than one pulseIn command it adds about 1 second of lag per pulseIn command. I am controlling a servo through this setup.
The code: Code:
#include <Servo.h>My attempt at using Interrupts: Code:
#include <Servo.h> |
Re: Arduino Mecanum drive using PWM?
http://forum.arduino.cc/index.php?PH...p ic=42462.60
Should Help, looks like there is an interrupt library developed for servo. |
Re: Arduino Mecanum drive using PWM?
I don't think that you'll be needing interrupts. The arduino is fast enough to control 4 PWM's. Also, don't use the unsigned longs. If forwardDuration is 10, strafeDuration is 100, and rotateDuration is 100, you will have a negative value for FR, which is unsigned. I don't know what happens on the arduino, but it may wrap around to some massive number.
EDIT: Depending on what you're using to control your motors, you may have better sucsess with analogWrite. Also, how are you testing to see the lag? |
Re: Arduino Mecanum drive using PWM?
Thanks for the help. I finally was able to load the arduino forums and now have my servos responding virtually instantly. I just needed to increase the timeout in the pulseIn function (the amount of time the arduino searched for a pulse coming in before moving on in the code).
|
Re: Arduino Mecanum drive using PWM?
Care to share your implementation? It may help other expri-mentors. Thanks.
|
Re: Arduino Mecanum drive using PWM?
I am planning on taking the pwm signals from my spectrum ar6210 and mixing them with the arduino using the following code to create a robot with a mecanum drive. For the motors I plan on using some continuous rotation servos and I am planning on buying some small mecanum wheels such as the 4in vex wheels.
Code:
#include <Servo.h> |
Re: Arduino Mecanum drive using PWM?
cad321,
A couple of observations regarding the I/O. The pulseIn code (source) looks like it will return a zero (0) when it does not find the pulse within the timeout period. You may want to put in some code to check for this, otherwise your outputs may not be what you would like. Also, be aware that your "loop" execution time will be variable depending on how long it takes to obtain the three pulse values and output to your four servos. Assuming a standard 20 millisecond interval for the incoming servo PWM value, you will probably have a range between 8 to 65 milliseconds. This may not be a problem. My knowledge of the hardware you are using is limited, but You may also want to review your mixing algorithm as well. Again, assuming a standard servo input (1-2 ms pulse), the pulseIn should return values between 1000 and 2000 (usec). Adding all three together for FL (for example) would yield 3000 to 6000, or basically your maximum all the time. This could be correct if the inputs are not what I assumed, but it doesn't look right for a standard servo input/output signal. My guess, based on your original post of the 1 second delays, indicate that you are probably not reading at least two of the signals (Strafe & Rotate perhaps?), so you are adding zero (0) to your forward value and the calculations are doing what you expect. The 1 second delay is approximately the timeout for the default pulseIn when it doesn't see a pulse and no explicit timeout is passed. Mike |
Re: Arduino Mecanum drive using PWM?
Quote:
Quote:
|
| All times are GMT -5. The time now is 03:02. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi