5
$\begingroup$

I'm building a 2-wheel balancing robot from old parts. DC motors from an old printer, wheels from a BBQ, bodywork from an old optical drive etc.

The brain of the robot is a Raspberry Pi 3. I'm using an L298N motor driver to control 2x 12-35v DC motors. Balance and movement will be 'sensed' using a 10DOF L3GD20 LSM303D Gyro, Accelerometer & Compass board. I'm currently using an Arduino with PWM for multi speed and direction of each motor. A PID loop will keep the robot balanced.

It looks like this: Raspberry Pi > Arduino > L298N > Motors

So far everything is good (don't worry I'm not going to ask "Where do I start??" :D)

My question is this: should I continue to control the sensors and motors' driver using the Arduino, having the Pi issue higher level commands to the Arduino, OR should I just let the Pi do all the leg work?

I'm trying to keep power consumption to a minimum but I want to keep the processing overhead of the balancing and movement away from the Pi. Additionally, I've read that an Arduino is better at this sort of work due to the fact that it has a built in clock, where a Pi doesn't. I assume the PID loop will be slowed if the device (the Pi) is working on other processing tasks like navigation and face recognition etc.

Are my assumptions correct and which direction would guys steer towards?

Your knowledge and wise words would be very much appreciated!!

$\endgroup$
1
  • $\begingroup$ If you were not going to send the feedback to the Arduino, then why would you use the Arduino at all? $\endgroup$
    – Chuck
    Commented Oct 24, 2016 at 17:21

2 Answers 2

4
$\begingroup$

If you want to have a good balancing, PID loop timing is very important. Standard Raspberry OS, like Raspbian can't guarantee you any precise timing, so once your loop period may be 10ms, once it can be 1s, resulting in a robot to fall. You can try to run some real time operating system on RPi, like FreeRTOS, that would have preemptive capabilities (so a process with high priority, like PID, would interrupt other, lower priority processes).

That being said, I think that using an Arduino is a very good choice, as it nicely separates high level processing, from low level control tasks.

$\endgroup$
1
  • $\begingroup$ To clarify one point half-asked in the initial question: a RasPi does have an internal clock, all computers need one to work. BUT, not all clocks are created equal. The software on the RasPi is not capable of 'real time' operations (where the time an operation is completed is critical, instead of starting and ending whenever it happens to). Arduinos technically aren't either, but for your use, they might as well be. Use the Arduino for balance, it can do so out of the box and without complicating the rest of your design (like loading FreeRTOS on the RasPi might do). $\endgroup$ Commented Oct 24, 2016 at 12:32
0
$\begingroup$

I was also faced with this dilemma. I was using Arduino to read Kp, Ki and Kd from potentiometers and transferring the data over Serial port to a Raspberry Pi. I found that I had to put a delay of atleast 20 ms on the Arduino side for the Pi to capture the data correctly. If I transmitted the data without any delay, the Pi was unable to cope up with the stream of incoming data. So I decided to do all the balancing and moving part on Arduino. I will use OPEN-CV for image processing and use Pi to send command over Serial port to navigate the robot.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.