Controlling 3pi Pololu Robot using a Joystick

One of my goal projects with the 3pi Pololu Robot is to control it using a Joystick.
I think this is a good idea. I just have a rough concept but any idea will be very welcome.
Using an old joystick, I think to…
1… scale the X and Y voltages and use them as analog inputs.
2…or scale and digitize those voltages using an ADC converter.

Then I think to replace the 0-255 (0- -255) speed ref values for joystick real variables in the 3pi firmware.



It’s certainly possible to control a 3pi using a joystick. I don’t see any actual questions in your post, however, so I’m not sure what kind of response you’re looking for.

- Ben

Thank you for your comment Mr. Ben.
I am trying to make time to start with this “small project” to control the 3pi
wirelessly using a joystick. Because of that, I will appreciate if you (as an expert in the I/O of the 3pi) could
enlighten me about where to start.
I already have created the algorithm using the X & Y ref voltages of a joystick to control two wheel of an ODV.


The simplest approach would probably be to use potentiometers for your joystick axes and feed the result into analog inputs on the 3pi. However, this is not a wireless solution. I think getting a wireless joystick working would be much harder, and the exact implementation will depend heavily on the exact joystick you are using. Can you tell me more about your joystick?

- Ben

I am using a Cyber-tech, Inc. Ergo-Grip Dual Axis Hall Effect Joystick Model JS-EG-930.
I have not develop yet the wireless interface but I coincide with you to start wire and
then move to wireless. This joystick requires 5 VDC input and 0.5 to 4.5 VDC output.


In that case, you can use analog inputs ADC6 and ADC7 on the 3pi to read your joystick channel voltages. These two pins are jumpered by default to hardware on the robot, but you can remove these jumpers to use the pins for your own inputs. The Pololu AVR Library makes it easy to read analog voltages on arbitrary analog inputs, so that part should be easy. I suggest you start by just trying to read the voltages from your joystick channels (you can display the readings on the LCD for easy feedback).

After that, you need a function to convert the readings into motor voltages. Assuming you want one joystick channel to control throttle (forward/reverse) and the other to control steering (left/right), you will need to mix the channel readings appropriately to get your motor speeds. Typically, this mixing is something like:

motor 1 speed = scale factor * (joystick ch 1 + joystick ch 2)
motor 2 speed = scale factor * (joystick ch 1 - joystick ch 2)

This assumes that joystick channel 1 is throttle and channel 2 is steering. Note that if the steering channel is zero, both motors are set to the same speed (the throttle channel), and if the throttle channel is zero, both motors are set to opposite speeds (set by the steering channel).

Does this make sense? If you have specific questions, please ask. Otherwise, I think you should just start playing around with it and asking questions as you run into trouble or come across things you don’t understand how to do.

- Ben

Thank you again Ben for your comments. It does make sense to me your explanation.
My Joystick in X and Y goes from 0.5 (Min) to 4.5 (Max). Origin or Average is 2.

I will try your approach that looks easier than mine but here a brief of it:

  1. Initialization:

A - SteeringInput (Input X Analog Voltage)
B - SteeringDeadBand 0.1 (For non Zero values when joystick in origin)
C - SteeringMax 4.5
D - SteeringMin 0.5
E - SteeringAvg 2
F - SteeringPercentOutput

G - ThrottleInput (Input Y Analog Voltage)
H - ThrottleDeadBand 0.1 (For non Zero values when joystick in origin)
I - ThrottleMax 4.5
J - ThrottleMin 0.5
K - ThrottleAvg 2
L - ThrottlePercentOutput 0

  1. For the Steering Control:
    Read A
    IF (A >= ( E + B )) THEN
    F = ((A - E - B) X 1000 ) / (C - E - B )

IF ((E - B) >= A) THEN
F = ((A - E + B) X 1000) / (D - E + B )

  1. Then do the same for the Throttle control…and so on.
    Once I get it work, I will transcribe it in full here.

Godspeed, Wilfredo

Today, I ran the first successful motion test of my 3pi using an old Quick-Shot joystick tied to the analog inputs ADC6 and ADC7 as Ben suggested. I can do throttle (forward/reverse) and steering (left/right) with speed control. Thanks Ben!

I wanted to share part of the system settings (code, electrical schematic) and a small video.

Here the electrical schematic:

Here the code:

// ODVG90E 10:53 AM 1/11/2012
// Controlling a 3pi with Snap-Shot Joystick

#include <pololu/orangutan.h>

int main()
	int pot1, pot2, motorSpeed1, motorSpeed2, LeftWheel, RightWheel;

	for (;;) {
		// functionality
		pot1 = analogRead(6);
		pot2 = analogRead(7);

		motorSpeed1 = (512 - pot1) / 2;
		motorSpeed2 = (512 - pot2) / 2;

		LeftWheel = (motorSpeed1 + motorSpeed2)/4;
		RightWheel = (motorSpeed1 - motorSpeed2)/4;

		set_motors(LeftWheel, RightWheel);

		// printing
		lcd_goto_xy(0, 0);
		print("   ");

		lcd_goto_xy(0, 1);
		print("   ");


An finally the video:

Thank you,

Hello Pololu gang! I just wanted to share my new project controlling wirelessly a 3pi using a simple X & Y joystick, a MiniMax C2 module, a couple of XBee modules and a laptop running Termite software as a bridge. Here the link of my video.

My next project pursues to eliminate the laptop as a bridge and use a XBee module with the joystick.

If you want more detail, please, just let me know. Thank you.

Humble, TX

Very cool; thanks for sharing your video! I look forward to hearing how it goes without the laptop.

- Ben

Hello. I finished my project about a wireless control (Via RF using XBee modules) of a 3pi using a 2-axis joystick.
I ride off the laptop that I was using as a bridge and implemented C codes for the MM51C2 and the robot.
The speed control has 128 steps. I have uploaded a small video of my control with a motion test. Feel free to ask questions.


I am glad to see you got it working without the computer. Looks like a very cleanly built project. The music in that video is creepy.

- Ryan

Than you very much for your comments Ryan. My next step is convert 3pi in a soccer robot. I am now developing the control system for his motion in the playground. My first goal is to make the robot to detect and approach to the ball. I have set a camera pointing from the ceiling to the playground (a table) and I am using a vision software to detect and track the robot and the ball’s coordinates. I am sending the X and Y coordinates of the robot (X2,Y2) and the ball (X1,Y1) to a microcontroller, where after some “magic calculations”, send throttle commands (forward/reverse) and/or steering commands (left/right) to the robot. Then, the robot will be capable of move from his current position (X2,Y2) to the ball (X1,Y1). One of my best approach for the two-points trajectory requires arc-tangent calculations. Sadly the MM51C2 does not handle trigonometry functions. I really would like to find a controller with that capability. DO you know if Pololu has something to help me here. My plan B is to use a brand different from Bipom. Thanks.

Many of our programmable controllers can do trigonometry. The controllers using AVRs (Orangutan or Arduino) can do trigonometry. The mbed controllers are quite a bit more capable, so if you need to do a lot of calculations quickly, you might consider them.

- Ryan

Thanks Ryan for your answer. Foreseeing the need of some trigonometrical calculations in my project, I chose an Arduino compatible module and keep the MiniMax51. Now, I can control the Pololu 3pi robot using the coordinates X and Y of the motion tracking of an object. To calculate the slope of the line between the ball and the robot (arc-tangent), I will use the Arduino compatible board. Here a video showing the control of one wheel of the 3pi. A web cam detects and track the red dot through a vision software called Roborealm. Then the X coordinate is send to the Osepp Uno (Arduino compatible) module. This module runs a C code and scales the coordinate X and generates an analog voltage proportional of the X value. This voltage is send to the MiniMax51 module (by Bipom) who reads the analog value and after another scaling, send it via XBee to the robot.

My next step is develop the code to make the 3pi to get closer to the ball.

Very nice. I like how you are methodically completing small steps (instead of trying to do it all at once!).

- Ryan


I was looking for the robot control using joystick.

I found this topic. But I need to know. Is there some article, thesis or book section about the formula (Y-X; Y+X)?



Hello, Ewerton.

I don’t know of any particular books or literature, but the formula comes from the superposition of two behaviors: the X channel controls turning in place (i.e. steering), and the Y channel controls driving straight (i.e. throttle).