Not entirely sure where to put this topic so someone please let me know if this is off topic for the forum category.
For my 4th year university honours project I am trying to build a pan/tilt camera unit which uses an onboard WiiMote to track an Infrared source.
I have managed to successfully connect the WiiMote to my MacBook using DarwiinRemote OSC available from Google Code (Google it for my info, the forum won't let me post a link on my first post ).
I also have managed to get the pan/tilt system to follow the source using some crude logic.
Now, herein lies my problem, the tracking motion is incredibly jerky, wobbly and just entirely inefficient. My logic at the moment is to get the co-ordinates of the source (or average co-ordinates if there are multiple sources) and then analyse their position relative to the centre (i.e: with the pan tilt unit looking dead on at the source) in Processing. I then instruct the Arduino (via Serial) to move the appropriate servo (pan or tilt) left or right/up or down a step. On the next loop I analyse the point again and do the same until the source is once again centred.
Quite often however the source will 'over jump' the centre causing the unit to compensate by moving back and then over jumping again and so forth in a constant loop.
I have seen many projects using the Wii Nunchuck with incredibly smooth and responsive movement so I'm wondering, and asking, if there is a better approach I could take?
I'm relatively new to the Arduino way of working so any advice or direction is extremely appreciated! Please ask me to repeat anything or post code if you feel it is needed - I don't even really know where to start!
This is my post, I used the wiimote's IR Cam directly from its I2C Bus (Where you plug in a Wii Nunchuck). I have code that is relatively smooth, you should give it a look. Tere is a video example of my code.
This is also done with Continuous rotating servos. With these you get speed control. By choosing PWM values further away from the 0 position, you get a faster rotation. I use an almost-real-time approach to following light sources. If it is located near the edge of the camera, it goes at a fast speed in that direction. If it's near the center of the camera, it goes at a much slower speed. If it is near enough to the cameras center, then the motor is stopped.
I'll have a video up that has both axis; the current one is for one axis.
What sort of hardware setup are you using? Your project does exactly what I'm trying to achieve and more. I'm essentially building a wiimote controlled tripod and whilst my efforts look pretty smart (from a build point of view) the movement is horribly jerky and single speed.
If it's ok with you I'd really like to use and mod your code (or work with you?) for this project.
For an idea of what I'm building see these blog posts:
No problem, do whatever you'd like with my code. I'll post the dual-axis code and vid up probably by tonight.
What kind of motors are you using? I used 14$ ones found on sparkfun. They have enough torque to move a wiimote, but I'm not sure if they'd handle too much more (for the verticle rotation).
Just saw the vid, looks like your servos work fine :0)
Sorry for the delay, i've been busy with other stuff.
I tried to apply your code to my setup today and failed quite miserably.
I'm not keen to (or really able to) modify the wiimote to read from the expansion port. As such I'm trying a wiimote -> (bluetooth) -> Processing - > (Serial - USB) - > Arduino approach.
I think I understand the logic and can have the Arduino respond to the correct commands but I can't get the servos to move at all.
I think I have standard servos (i.e: approx. 180 degree motion). I have in the past always controlled them by telling them to go to a specific place (i.e: myservo.write(90)). Can I still sue these servos in the manner you suggested? Or am I really looking at taking everything apart and installing new servos - something I want to avoid if possible.
Got my hands on some new servos. Testing them out and I have come across this issue: the wiimote continuously overshoots and tries to compensate accordingly resulting in a loop of jerky back and forth.
Did you have any issue like this? I'm not using the same hardware setup as you (see above) but don't see why it would make a difference....? Maybe I'm missing something.
If you are using my EXACT code then I'm positive of what the problem is;
-Different servos have a different "0" position. In my case, "0" was at PWM 1500. Some servos will have a larger range of pwm signals they respond too. I bought 2 continous rotation servos; one from Sparkfun.com, and one from Adafruit.com. Sparkfun's range was from 1000 - 2000, while Adafruit's was from 1300 to 1700. You have to test your motors to see what their range are, and figure out the best possible PWMs to allocate as Slow, Medium, and Fast.
If your Slow speed is not slow enough to rotate in small increments, it will overshoot ever time back and forth. Another way to resolve this is to increase the range in which you set the servos at the "0" position (to stop the servos). In my case I think I set the Stop PWM to occur when the light sensed was ~ 450 < ircamBlob1.x < 550. Increasing that gap (right now its at 100) would let the "faster" PWMs be able to catch the sensed light within that range.
I think you should experiment with your servo speeds (example keep the Slow speeds closer to your servos ZERO position