2

I need to test my computer vision stack written in C++ on a mobile robot and I need to control the robot from a Linux ARM board (which can be a Raspberry Pi). Since the specialized wheeled robot platforms are quite expensive (RobotShop lists few, usually chassis only without motor, steering servo etc.) and since I would like to use a normal 4-wheeled platform with steered front wheels I am thinking about using an ordinary ready-to-ride RC car. I am all new to both RC modelling and electronics hacking, could someone give an introduction of what I need to buy and do?

Can I use a Himoto RTR car for instance? I inspected few of them, the most affordable ones seem to have the RC receiver and steering servo integrated into one piece (like this car) and I really do not know if that is an issue since I guess I will need to replace the RC receiver with the RPi...

I need help with how to interface from the RPi to the car (motor + steering servo). I read about following:

  • PWM (Pulse Width Modulation)
  • PPM (Pulse Position Modulation)
  • brushed and brushless motors
  • ESC (Electronic Speed Controller)

Seems like servos and brushed motors use PPM while brushless motors use PWM. I am interested in both brushed (cheap) and brushless (good endurance) motors. Can someone suggest a hardware I need to use for both RC model part and RPi part? Do I need a special shield for RPi because of the motor/servo?

On the software side, since my vision stack is in C++ the best would be to be able to control the RC car from C too (no Python etc.).

I plan to use a gamepad with 2 joysticks to be able to control the car, either connected directly to USB on the RC car's RPi or on another RPi and using wifi transmission. I think I can deal with this gamepad part alone... just need help with the motor/servo stuff.

Thanks for help in advance!

  • You might need to control the motors directly. Manufacturers usually don't upload code about their hardware. – PNDA Feb 20 '16 at 8:09
  • I'm not sure what the question is but it seems like it would need a complete book to respond. – joan Feb 20 '16 at 9:21
  • Yes it is a tough topic for me that's why I am asking. I guess the answer may be short but probably needs a lot of know-how. I cross-posted the post to Robotics SE too since it also is relevant there. – Kozuch Feb 20 '16 at 14:15
1

This isn't truly an answer (because there is a lot of variability), just some hints for getting started

This SHOULD be possible. But is highly dependent on your hardware. You have to determine what kind of motors the car uses. My guess is some DC motor for propulsion and if it has proportional steering a servo. (Cheap cars might use some kind of DC motor that just locks at full left/right angles with a physical mechanism on the steering head). Once you determine your exact motor type start research into how to control them. Different motors require very different control schemes. Servos use PWM to set the angle, DC motors simply use voltage to set speed, steppers use a series of specific pulses, etc.

It might be best to start with the working rc car, hook it up to an oscilloscope and send it controls. See what happens when you turn right, what input does the motor get? Try turning left. Then try forward and backward. etc. But usually just probing signals isn't enough. You also need generic knowledge of motors. Combining the knowledge of the existing system with the generic motor theory should help you figure out how to make your own controller.

Ror real-time constraints, the RPi itself has some issues, it doesn't have a hardware PWM for instance. This may or may not be a problem. You have a few options, you can find motor drivers at places like sparkfun.com or adafruit.com (if you are in the US) that use common protocols like i2c/SPI for control. In this case your RPi is the brains, the motor controller is its slave, and you only need the actual motors from the RC car.

Even besides the real-time constraints, you usually can't run motors directly from an MCU, motors can be noisy, or require very high current/voltage that a mcu typically can't handle. You will almost certainly need some kind of interface hardware between the MCU/Pi and the motors

Anyway I hope this helps you get started or gives you some ideas about how to approach the problem, good luck.

0

Thanks andrew for a general answer. Finally, I was able to figure out a more concrete solution myself. As suggested by this post on Electronics SE, controlling both the ESC that drives the DC brushed motor and the steering servo should be possible with the "standard" 50 Hz and 1-2 ms PWM servo control scheme. This should probably apply to most of the RC cars on the market.

So the problem boils down to controlling two servos from C on a Raspberry Pi. This can be done in numerous ways. I will list the options here:

Using RPi's software or hardware PWM

WiringPi has some software PWM options but they are said not to be ideal for servos. This answer mentions things like servoblaster and pigpio, which should be more reliable since they use DMA for (probably SW PWM) timing and at least pigpio can also do HW PWM. Most newer RPis are said to have 2 HW PWM channels which is what RC car needs. I did not check servoblaster but pigpio's C gpioHardwarePWM function (I did not test it yet though) seems to be able to do HW PWM. Like this, RPi should be able to control the car by itself.

Using additional hardware/shields

Given the above option is working using additional HW should only give you more servo channels which is really not needed for an RC car, but may come in handy for other RC stuff (planes, quads etc.).

There is the Adafruit 16-Channel 12-bit PWM/Servo Driver which is based on PCA9685 and uses I2C, but they only offer Python code. For a C implementation one would probably need to rewrite their Python stack to C and control the board by I2C from C.

A truly cross-platform C solution are Pololu Maestro USB/UART servo controllers which have official Linux support (Linux driver and C example) and should run on Raspberry Pi.

Both of the additional HW options use HW PWM so they should be really reliable.

Using gamepad for control input

A common gamepad with 2 joysticks is a goog choice for custom "radio controller". Linux/RPi has a good joystick support and it should be fairly easy to read it from C. Use jstest (see here) to check device compatibility. My cheap Speedling gamepad worked but had rather bad joystick sensitivity/resolution around zero positions. Then I tried PS3 Sixaxis (guide here) with a cheap i-tec USB bluetooth dongle - it worked nicely and had much better sensitivity around neutral positions. Follow the first example in mailing list tutorial (linked from here) for a working joystick input source code.

Conclusion

I guess this is all what is needed for RC car control. One needs to write the interconnect between the gamepad and PWM parts and compile them together for a working solution. The compilation should be fairly easy since there are no real dependencies I guess.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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