# RoboCup 2014

The RoboCup 2014 was held in João Pessoa (Brazil). Here are some pictures taken during the event:

# Geometric model for differential wheeled mobile robot

In the following, the geometric model is a mathematical transformation where the inputs are the angular velocities of the wheels (usualy measured with encoders) and the output is the pose (position and orientation) of the mobile robot in the working space.

## Problem specification

We focus here on a differential wheeled mobile robot. Such robot is composed of two wheels aligned on the same axis. Here is an illustration of Rat-Courci, a small differential wheeled robot designed for the Micromouse competition:

The wheel diameter is given by $D=2.r$ where $r$ is the radius. The distance between the center of the robot and the wheels is given by $l$, the distance between wheels is $2.l$ according to the following illustration:

We’ll assume that the following parameters are known:

• $r$ is the radius of the wheels

• $l$ the distance between the center of the robot and the wheels

• $\omega_l$ and $\omega_r$ are the instantaneous angular velocities of respectively the left and right wheels

Our goal is to calculate the pose of the robot according to the upper figure:

• $x$ and $y$ are the coordinates of the robot

• $\psi$ is the angular orientation of the robot

## Elementary displacement calculation

First, let’s calculate the linear velocity of each wheel:

$\begin{array}{r c l} v_l &=& r.\omega_l \\ v_r &=& r.\omega_r\end{array}$

The average velocity of the robot is then given by:

$v_{robot}=\frac {v_l + v_r} {2}$

The robot velocity can now be projected along the $x$ and $y$ axes:

$\begin{array}{r c l} \Delta_x &=& v_{robot}.cos(\psi)&=&\frac {r}{2} ( \omega_l.cos(\psi) + \omega_r.cos(\psi))\\ \Delta_y &=& v_{robot}.sin(\psi)&=&\frac {r}{2} ( \omega_l.sin(\psi) + \omega_r.sin(\psi))\end{array}$

The angular velocity of the robot is given by the difference of the wheels linear velocities:

$2.l.\Delta_{\Psi}=r.\omega_r - r.\omega_l$

Previous equation can be reformulated as:

$\Delta_{\Psi}=\frac {r.\omega_r - r.\omega_l} {2.l}$

The elementary displacement of the robot is given by the following relation:

$\left[ \begin{matrix} \Delta_x \\ \Delta_y \\ \Delta_{\Psi} \end{matrix} \right]=\frac{r}{2}.\left[ \begin{matrix} cos(\psi) & cos(\psi) \\sin(\psi) & sin(\psi) \\\frac{1}{l} & \frac{-1}{l}\end{matrix} \right].\left[ \begin{matrix} \omega_r \\ \omega_l\end{matrix} \right]$

## Absolute position

The absolute position can be calculated thanks to the following equations :

\begin{array}{r c l}
x_{i}&=&x_{i-1}+\Delta_x \\
y_{i}&=&y_{i-1}+\Delta_y \\
\Psi_{i}&=&Psi_{i-1}+\Delta_{\Psi}
\end{array}

where

• $x_{i}$ and $y_{i}$ are the coordinates of the robot at time step $i$

• $\Psi_{i}$ is the orientation of the robot at time step $i$

Of course, this model has some limitations. The result is highly dependant on the accuracy of the robot (mechanical assembly, wheel diameter, distances …). We assume that wheels rotate without any slippery problems which is not true in practice. We also assume that the sampling rate is fast enough to assume that $\Delta_x$, $\Delta_y$ and $\Delta_\Psi$ will remain elementary displacements.

# PI-based first-order controller

## Introduction

The aim of this post is to explain and demonstrate how to calculate a simple PI controller for a first-order system. Let’s assume that the system is given by its transfer function $G$. The closed loop system is given by the following diagram:

## Close loop transfer function

The transfer function of the system is given by:

$\frac{y}{y_c} = \frac {CG}{1+CG}$

as $G$ is assumed to be a first-order system, its equation is given by:

$G=\frac{b}{z-a} = \frac{b} { z-e^{-\Delta/\tau} }$

where $\Delta$ is the sampling time, and $\tau$ the time constant of the open loop system.

$C$ is the PI controller, its equation is given by:

$C=K . \frac{z-a}{z-1}$

The transfer function of the closed loop system is now given by:

$\frac{y}{y_c} = \frac { K \frac{z-a}{z-1} \frac{b}{z-a} }{1+ K \frac{z-a}{z-1} \frac{b}{z-a}}$

Previous equation can be simplified:

$\frac{y}{y_c} = \frac { K \frac{b}{z-1} }{1+ K \frac{b}{z-1} }$

The new transfer function is given by:

$\frac{y}{y_c} = \frac { Kb }{ z -1 + Kb }$

## Static gain of the closed loop system

Let’s consider the response of the closed loop system when the input is a unity step ($\frac{z}{z-1}$):

$y(z) = \frac { zKb }{ (z -1 + Kb)(z-1) }$

According to the final value theorem for Z-transforms, the static gain of the system is given by :

$\lim\limits_{z \to 1} (z-1).y(z) = \lim\limits_{z \to 1} \frac { zKb(z-1) }{ (z -1 + Kb)(z-1) } = \lim\limits_{z \to 1} \frac { zKb }{ (z -1 + Kb) } = 1$

The static gain of the system is equal to 1, the static error will be equal to zero.

## Time constant of the closed loop system

The closed loop system is also a first-order :

$\frac{y}{y_c} = \frac { Kb }{ z -1 + Kb } = \frac { Kb }{ z - e^{-\Delta/\tau_c} }$

where $\Delta$ is the sampling time, and $\tau_c$ the time constant of the closed loop system. Note that $\tau_c$ can be less than $\tau$ (the time constant of the open loop system). If $\tau_c<\tau$ the system is more reactive (but is also more energy consuming). In practice, $\tau_c=\tau/2$ is a good compromise. From the previous equation :

$1-Kb = e^{-\Delta/\tau_c}$

and :

$K= \frac {1-e^{-\Delta/\tau_c}} {b}$

To get the same response time in closed and open loop, the previous equation becomes :

$K= \frac {1-a} {b}$

## Stability

The system is stable if all the poles are located inside the unity circle. Here, as the system is a first-order, there is one pole : $1-Kb$. The system is stable if:

$-1<1-Kb<1$

The previous equation can be rewrite as:

$0
and:=””
$="" 0
=”” note=”” that=”” if=”” $="" k="" is="" calculated="" from="" \tau_c="" (="" {1-e^{-\delta="" \tau_c}}="" {b}=""$),=”” the=”” term=”” $e^{-\delta="" \tau_c}$=”” included=”” in=”” $[0,1[$=”” and=”” system=”” necessarely=”” stable=”” because=”” it=”” leads=”” to=”” $0.=”” Discrete-time function
! (z-1)u(z) = K(z-a)\epsilon(z) ! z.u(z) – u(z) = K.z.\epsilon(z) -K.a.\epsilon(z) ! z.u(z) = K.z.\epsilon(z) – K.a.\epsilon(z) + u(z)$Let$! u_{n+1}= K\epsilon_{n+1} – K.a.\epsilon_n + u_{n} $or :$! u_{n}= K\epsilon_{n} – K.a.\epsilon_{n-1} + u_{n-1} 

## Acknowledgements

I want to thank Laurent Hardouin from the University of Angers for his help and explainations.

# Gameduino shield and Arduino Mega 2560 (or ADK)

Using the Gameduino shield with the Arduino Mega 2560 (or ADK) needs an additional wiring : the SPI bus must be wired to pins 11,12 and 13:

• pin 51 (MOSI) is connected to pin 11,
• pin 50 (MISO) is connected to pin 12,
• pin 52 (SCK) is connected to pin 13.

# Inside the maxon EC brushless DC motor

This serie of pictures shows how are made the Brushless Flat DC motors from Maxon. This is an EC45 flat (reference 339285):

The cap can be removed:

Magnets are located in the cap (black ring):

12 windings (4 series of 3 phases):

Three hall sensors are located between windings:

The cap is monted on ball bearings:

Top of cap (with printed references):

# Open and closed loop

## Open loop

Let’s consider the following system in open loop:

The transfert function of the system is given by:

$\frac {y}{u} = G$

## Closed loop

Let’s now consider the same system in closed loop:

The error $\epsilon$ is defined by the difference between the reference (expected value) and the output of the system (the real value):

$\epsilon = y_c - y$

The output of the system is given by:

$y=G.u=G.\epsilon$

By replacing $\epsilon$ in the previous equation we get:

$y=G.(y_c - y) = G.y_c - G.y$

This equation can be rewritten to get the transfert function:

$\frac{y}{y_c} = \frac {G}{1+G}$

## Closed loop with controller

Let’s now assume that a controller is added:

We can deduce the new transfert function:

$\frac{y}{y_c} = \frac {CG}{1+CG}$

# Introduction to EAGLE – Adding copper pour

## Copper pour

The copper pour outline is drawn with the POLYGON command:

Select the POLYGON tool. If the copper pour needs to be attached to a net, you can enter the net name straight after selecting the tool and validate with the Enter key:

It is still possible to modify the connection by right clicking on the edge of the polygon, in the contextual menu, select NAME. In the pop-up window, replace GND by the label of the new connection. This is also useful to check that the connection has been successfully done.
Left-click to draw polygon edges and double click to close the polygon. Once the outline is drawn, it appears in dotted lines:

Click the RATSNETS to calculate the copper pour:

The board should be updated. When the board is modified, the copper pour is not always recalculated. It is usefull to remember that RATSNETS force the calculation of the copper pour.

## Board outline conflict

According to your design check rules, the copper pour may sometime not reach the board outline:

This can be solved by setting the distance between the copper pour and the dimension layer equal to zero. Click on DRC, select tab Distance and set the distance equal to 0:

## Attaching a net

Before attaching a net to the copper pour, it is sometime usefull to unroute the existing tracks already routed. Use the command RIPUP, for example “RIPUP GND”, to unroute all the tracks named GND.
To add or change the copper pour net attachment, select the NAME command and click on the polygon. A window pop up and the user can modify or specify the name of the copper pour. When the name is the same as an existing track (for example GND), an electric connection is automaticaly created between the track and the copper pour. On the following board, the copper pour is connected to the groung:

## Remove copper pour

To definitively delete the copper pour, since the polygon is attached to the copper pour, delete the polygon. To temporary remove or hide the copper pour, select the RIPUP tool and click on the polygon. It removes the copper pour while keeping the polygon (dotted lines). Click RATSNETS again to recalculate the copper pour.

# Introduction to EAGLE – Adding mounting holes to a PCB

## VIA versus HOLE

There is two ways (via or hole) to add a mounting hole in a PCB and the difference between the VIA and the HOLE tools can be confusing.
A via is composed of a hole and a copper area surrounding the hole. But the main différence between vias and holes is the electric connection made between layers by the via. The HOLE tool just place a hole in the design without copper or connection. Depending on what the mounting hole is made for, you may add a VIA or a HOLE. The following capture shows the difference between vias and holes. On the left side of the PCB, holes has been added, and on the right side of the board, two vias has been placed.

As it is illustrated on the following figure, vias are isolated from copper pour:

## Hole diameters

Regardless the selected tool, the hole diameter has to be defined. The PCB editor is generaly configured in mils (or inchs) and the fastening specification is generaly provided in millimeters.
The following table is a quick references of most used diameters.
[mil][mm]
19.68504 mils0.5 mm
23.62205 mils0.6 mm
27.55906 mils0.7 mm
31.49606 mils0.8 mm
35.43307 mils0.9 mm
39.37008 mils1.0 mm
43.30709 mils1.1 mm
47.24409 mils1.2 mm
51.1811 mils1.3 mm
55.11811 mils1.4 mm
59.05512 mils1.5 mm
62.99213 mils1.6 mm
78.74016 mils2.0 mm
86.61417 mils2.2 mm
110.23622 mils2.8 mm
125.98425 mils3.2 mm

If the value is not listed, check this link : Distance converter.

# Introduction to EAGLE – Part 3 – Board editor

It is here assumed that the reader had studied the part 2 and that the schematic has been processed. The board editor should now look like this illustration:

## Forward and backward annotation

Check that the schematic editor and the board editors are open simultaneously. Save both designs and close the board editor. The schematic editor display the following message : “Forward and backward annotation has been severed !”:

A key element is that EAGLE maintains the link between the schematics and the PCB. When a modification is perfomed in the schematic, the PCB is immediatly updated (forward annotation). In the same way when the PCB is modified, the schematic is updated accordingly (backward annotation). It prevents the project from splitting into incompatible parts. The downside is that the designer have to consider it while working.

## Workspace

The board editor environment is very similar to the schematic editor (user interface arrangement is almost the same). As it was done for the schematic editor, display a grid of 50 mils in the board editor. Now select the WIRE tool to draw the board outline. Above the working area an horizontal menu bar is displayed. This is the wire properties. Set the layer to 20 (Dimension) and select a width of 10 mils. Note that the unity of the editor is set by the unity of the grid.

Left-click on the origin of the working area (coordinates 0,0), now click at coordinates 1600,1000 and finaly double click anew on the origin (right click at each point while defining the outline changes the wire bend style). The board outline should now be visible in grey:

It is convinient to remember that the mouse wheel allows you to zoom in and out and the middle button allows you to drag your design to another place (middle button has to be maintained pressed while moving the mouse).

## Placement

As for the schematic editor, the MOVE tool is used for moving components. The view displayed in the board editor is a top view of the PCB. Item drawn with the red color are located on the top side (component side) and item drawn in blue are located on the bottom side (copper side). To transfer a component on the other side, use the MIRROR tool. Select the tool, and click close to the origin (white cross) of the component to transfert. Place C2 on the bottom side, and C3 on the top side.

As for the schematic editor, when moving a component left-click places the component, right-click perfoms a rotation. While placing the components, it is possible to update the ratsnets (i.e. calculate the shortest airwire for each connection) by clicking on this icon:

Place the components according to the following arrangement and update the ratsnet.

## Routing

Routing consists now in transforming the airwires into routed copper-made tracks. It is done with the help of the tool ROUTE:

To create a new track, select the routing tool and click on the airwire you want to route. The track appears while moving the cursor. Right-click change the wire bend style as for nets in the schematic editor. Double-click ends the operation. By changing the layer above the upper left corner of the working area while routing, it switchs the track from one side to another and automaticaly add a via if necessary. You can save a lot of time using the middle button of the mouse to switch from ont to another layer.
The inverse tranformation (from tracked route to airwire) is not done with the DELETE tool. This action removes the connection. While forward and backward annotation is enable, deleting a connection is not possible from the board editor; it must be done in the schematic editor. To unroute a track, use the RIPUP tool:

It is usefull to remember that selecting an airwire with RIPUP converts all adjacent routed wires and vias into airwires, up to the next pad, smd or airwire. Thus, by left-clicking twice on a track it quickly unroutes the connection. Tracks and vias can be moved with the MOVE command. Selecting a wire segment near an end point will move the end point of the track. Selecting the wire in the middle will move it in parallel. Note that to move components there origins have to be displayed (layer 23 (tOrigins) and 24 (bOrigins) for components respectively on top and bottom layers).
With the SPLIT command you add a bend in a wire. It is usefull to push or modify an existing track:

Route the board according to the following illustration (track width is 50 mils):

## Modifying the board

The CHANGE tool allows you to change any property of your design. When selecting the CHANGE tool, a contextual menu appears with the list of properties:

Select WIDTH > 10 and click on any track of your design. The track width is modified. You can reverse the action with the UNDO command (Ctrl-Z). Note that modifying component names or values can’t be done with the CHANGE tool, it must necessary be done with the NAME and VALUE commands as in the schematic editor. Set the value of resistor R3 from 680 to 470 and check in the schematic that the value has been back annotated:

Perform the inverse action from the schematic editor and check that the board has been updated. Note that when you apply and action to an object that is too close from another, the software is enable to guess which is concern. In this situation, a single object is highlighted and a right-click allows to switch to the another potentially concerned object. Left-click finally applies the action to the current highlighted object.

## Design rule check

Before manufacturing the PCB, it is safe to check the design thanks to the DRC (Design Rule Check). First click on the DRC icon.

The DRC configuration window appears. The designer can specify its own project design rules. Once the rules are configured, click the CHECK button to start the Design Rule Check. When there is no error, a message is simply display at the bottom of the board editor. If existing errors are found, a window appears:

Here two errors are detected. The hole size of the vias is too small according to the design rules. By selecting one of the error, the problem is highlighted in the design:

With the CHANGE command, change the drill diameter of the vias from 23.62205 to 27.55906. Check again your design, you should, at the bottom-left corner of the window, have the message : “DRC: No errors”. Your design is ready for manufacturing.

# Introduction to EAGLE – Part 2 – Schematic editor

In this tutorial the reader will be guided to create a simple PCB, first lets start by creating the schematics.

## Workspace

Before starting the schematic, lets insert a frame containing title, date, author … On the vertical tool bar located on the left side of the window, click on the ADD icon. The ADD action allows to add new item in the design. It is largely dedicated to the insertion of new components.

A window pops up and display all the available libraries. In the search entry located at the bottom left of the window, type “frame” and confirm with the Enter key :
The list of libraries is now limited to entries containing the string “frame” in there title or description. Select the A4L-LOC which is a DIN A4 Landscape frame and click OK. The frame is now attached to the cursor, place the frame in order to align the bottom-left corner of the frame at coordinates 0,0. Coordinates are displayed in the upper left corner of the working area. The origin is also display in the working area with a small dotted cross. When the frame is placed, left click with the mouse and hit twice the “Esc” key to exit.

Save your design and change the view by clicking on “Zoom to fit”. You should now have a general view of your future design.

Click on the grid icon:

The grid setting window appears, in this window, you can set the grid parameters (size, style, etc.). Set display “On” and click “OK”. Your workspace is prepared for the schematic and should look like this:

Click to the ADD icon as explained previously for adding the frame. EAGLE is provided with a large number of librairies, and the user can enter one or more search patterns in the search field by using special characters (wild cards) ‘?’ and ‘*’:

• * is a search pattern that can be replaced by one or several characters. For example *555 will provide all the entries ending by 555. 555* will provide all the entries beginning by 555 and *555* will provide all the entries containing 555.
• ? is a search pattern similar to ‘*’, excepted that it can only be replaced by a single character.

It is usefull to remember that when you add a device, right click rotate and left click place the symbol. Once a symbol is placed, several operations are still possible :

Search and add the following components in your design (the belonging library and package is mentioned in brackets) :

Component
LibraryDevicePackage
555 timerst-microelectronicsNE555DIL-08
ResistorrclR-EU0204/7
Polarized capacitorrclCPOL-EU2,5-6EE2,5-6E
CapacitorrclC-EUC1206C1206
Screew terminalcon-ptr500AK500/2AK500/2
5mm LEDledLED5MMLED5MM
VCC supply symbolsupply2VCC-
GND supply symbolsupply2GND-
Note that, even if VCC and GND are provided for convience and are not real components, they can be found in the libraries. Add and place your components in order to get the following arrangement:

The electrical connections have to be drawn with the NET tool (or the bus tool for buses). The WIRE tool also draw lines, but it is not dedicated to electrical connections, it belongs to the drawing tools (text, circle, arcs…).

Once the NET tool is selected, add a connection by clicking on the first pin to connect. Place the cursor on the second pin or junction, and right click without moving the mouse : the wire bend style will automaticaly change. It can also be done by selecting one of the wire bend style icon:

Place the connection according to the following schematic. This is a very simple NE555-based LED blinker:

## Component name and value

The following icon (NAME) allows the user to change a component name :

In the same way, the VALUE icon allows the user to add or modify the component value (when applicable):

Rename and set values of each symbol according to the following illustration:

## Check errors

Once your schematic is finished, it is safe to use the ERC (Electric Rules Check) tool. It can detect many mistakes in the design (wrong connections, non compatible junctions …)

.

A new window pops up, and displays four warnings:

The first one says that the pin 8 of the NE555 is called VCC+ and is connected to VCC. The three others say that the frame, the LED and the screw terminal don’t have values. As none of this four warning is an error, the four errors can be approved. The dialog box should now display zero error, zero warning and four approved:

## Generating board

When the schematic is finished and checked, the board can be created. Click on the following icon to generate the board and launch the board editor.

EAGLE may ask you to confirm the creation of a new board from your schematic, answer yes and the PCB is automatically prepared for routing:

# Introduction to EAGLE – Part 1 – Control panel

Eagle stands for Easily Applicable Graphical Layout Editor. It is an electronic CAD software manufactured by CadSoft Computer GmbH, a German company, since 1988. This software is provided with, among other, a schematic capture editor, a PCB (Printed Circuit Board) layout editor, an auto-router, a Computer-Aided Manufacturing (CAM)… It supports Windows, Linux and Mac OS X. This tutorial has been prepared under version 6.5.0 / Ubuntu 12.04 LTS

## Control panel

When EAGLE is started, the following window appears on the screen,this is the control panel, the EAGLE starting window.On the left hand side of the window the user manage existing and new projects and can get an overview about the libraries and settings :

• Libraries: this entry lists libraries of components, each component is composed of a schematic and a footprint linked together.
• Design Rules: the user can tune the parameters relevant to the board and its manufacture.
• User Language Programs: this is C-like programs that can be used for a variety of tasks. It can be used, for example, to modify your project and automize certain tasks.
• Scripts: the user can execute sequences of commands that are stored in a script file. It provides the ability to customize the program according to your own wishes (assign keys,
load pc board shapes, change colors…)
• CAM Jobs: CAM stands for Computer-Aided Manufacturing. It generates output data for the manufacturing tools (for exemple exporting Gerbers files which is the most used professional format).
• Projects: this entry lists the examples and projets. When a new project is created, it is automaticaly added in the tree.

The Arduino MEGA2560 board has been designed with EAGLE. It is provided within the examples:

## Directories

Basicaly, EAGLE stores all the projects and necessary files in the same main folder and creates subfolders to differenciate each projet. In the main menu bar, select Option > Directories:

The following interface allows the user to configure directories. $EAGLEDIR represents the path to the main folder (on my installation it is located in /home/username/eagle-6.5.0/). When a new project is created, a new folder is automatically added in$EAGLEDIR/projects/ . The user can specify several folders. It is possible, for example, to have the default libraries available on a network server, and the personal projects in private local folders.

Before continuing check that the folder for libraries is configured with the following path: \$EAGLEDIR\lbr.

## Libraries

On the left hand side of the control panel, click on Libraries to develop the tree and select the library 74xx-eu.lbr. This library is dedicated to TTL Devices (74xx Series from Texas Instruments). Select a device, on the right side the symbol and footprint appear:

## New project

To create a new project, select File > New > Project :

A new project is automatically added on the left hand side of the window under the branch Project/eagle. Enter you project name, for example FirstPCB :

Right click on the project and select New > Schematic.

A new window is automatically open, this is the Schematic Editor:

# Online motor sizing calculator

The following calculator allows you to size motors for a mobile device. It is strongly recommended that you read this page before any use for a better understanding of the calculator.

# Eagle 6.5.0 installation on Ubuntu 12.04 LTS 64 bits

When trying to install eagle on Ubuntu 12.04 LTS 64 bits I encounter the folowing error:

line 108: /tmp/eagle-setup.9094/eagle-6.5.0/bin/eagle: No such file


This error is due to missing packages and can be resolved by processing the following commands before installing:

sudo apt-get install libssl1.0.0
sudo apt-get install libcrypto++9
sudo apt-get install build-essential perl gcc-multilib
sudo apt-get install ia32-libs lib32z1 lib32z1-dev


# Arduino-based accurate distance measurement with Sharp sensors.

The aim of this post is to explain how to convert voltage from Sharp ranging sensor into an accurate distance. Experiments have been performed with Sharp GP2Y0A02YK and GP2Y0A21YK sensors. The range of this triangulation-based sensors are respectively from 20cm to 150cm and from 10 to 80cm.

## Measurement survey

An accurate measurement survey has been performed. Range is mesasured with a step of 10mm. The following graph show the behavior of the GP2Y0A02YK sensor according to the distance. As it is explained in the sensor’s specifications the sensor is not suited for measurement below 20cm. This range can even not be exploited due to the ambiguity.

Same methodology and graph for the GP2Y0A21YK sensor below:

## Polynomial approximation

Thanks to the Matlab polyfit fonction, the curv (for the GP2Y0A02YK) has been approximated with a fourth degree polynomial. The approximation covers the range from 14cm to 150cm. The following figure shows the result.

For the GP2Y0A21YK a fifth degree polynomial was necessary:

## Results

The approximation for the GP2Y0A02YK is given by the following equation. $ADC$ is the raw value returned by the Arduino analogRead() function.
$Distance = 2583.711122992086 - 20.197897855471.ADC + 0.071746539329.ADC^2 -0.000115854182.ADC^3 +0.000000068590.ADC^4$


The same approximation for the GP2Y0A21YK is given by:

$Distance = 200.3775040589502 -2.2657665648980.ADC + 0.0116395328796 .ADC^2 -0.0000299194195.ADC^3 + 0.0000000374087 .ADC^4 -0.0000000000181.ADC^5$

Based on this result, a C++ function can easily be written in order to compute the distance:
/*!
\brief  make a distance measurement with a Sharp GP2Y0A02YK sensor
\return the measured distance in mm

*/
float get_Sharp_GP2Y0A02YK_Distance(int PinID)
{
// Read analog to digital converter value

// Convert in millimeters and return distance
return  2583.711122992086
}


For the GP2Y0A21YK :

/*!
\brief  make a distance measurement with a Sharp GP2Y0A21YK sensor
\return the measured distance in mm

*/
float get_Sharp_GP2Y0A21YK_Distance(int PinID)
{
// Read analog to digital converter value

// Convert in millimeters and return distance
return  200.3775040589502
}


## Acknowledgements

Nothing of this would never have never see the light without Evan Guedon, Benjamin Buffard, Julien Thielleux, Rémi Gourdon and Nicolas Delanoue.

# Sizing motors

This article is dedicated to motor sizing. Althrough it is dedicated to robotics and electrical motors, it can easily be extended to any application or other kind of motors.

## Problem specifications

Let’s consider a wheeled robot that climb up an inclinated plane:

Figure a.

The wheeled robot illustrated on figure a. have the following specifications:

• weight $m$[$Kg$],
• wheel diameter $D$[$m$],
• maximum velocity of the robot $v$[$m.s^{-1}$],
• maximum acceleration of the robot $a$[$m.s^{-2}$],
• angle of the greater positive slope to climb up $\alpha$[$rad$],
• gear ratio between the motor and the wheel $R$.
• efficiency of the gear box $\eta$.

Properties to determine :

• torque on wheel shaft $\tau_{wheel}$[$N.m$],
• torque on motor shaft $\tau_{motor}$[$N.m$],
• angular velocity of wheel shaft $\omega_{wheel}$[$rad.s^{-1}$ and $rpm$],
• angular velocity of motor shaft $\omega_{motor}$[$rad.s^{-1}$ and $rpm$],
• power of the motor $P_{motor}$[$W$].

## Angular velocities

Let’s first calculate the angular velocity of the wheel:

$\omega_{wheel} [rad.s^{-1}]=\frac{2v}{D}$

The angular velocity of the motor shaft is given by:

$\omega_{motor} [rad.s^{-1}]=R.\omega_{wheel} =R.\frac{2v}{D}$

The angular velocities converted in rotations per minutes are given by:

$\begin{array}{r c l} \omega_{wheel} [rpm] &=& \frac{60.v}{D.pi} \\ \omega_{motor} [rpm] &=& R. \frac{60.v}{D.pi}\end{array}$

## Torque on wheels shaft

Torque is more tricky to calculate. The fundamental principle of dynamics gives us:

$\sum \vec{F_i} = m.\vec {a}$

Forces acting on the robot are gravity and actuator. The force inducted by the gravity is $\vec {F_{Gravity}}=m.\vec{g}$. When projected on the direction of motion (see figure a.), the force inducted by the gravity is given by:

$\| \vec{F_g} \|=m.g.sin(\alpha)$

The fundamental principle of dynamics can be rewritten as:

$m.a = \|\vec{F_m}\| + \|\vec{F_g}\| = \|\vec{F_m}\| - m.g.sin(\alpha)$

$\|\vec{F_m}\|$ can be deducted :

$\|\vec{F_m}\|=m.a + m.g.sin(\alpha)=m.(a + g.sin(\alpha))$

Thus, the torque on wheel’s shaft is given by:

$\tau_{wheel} = \|\vec{F_m}\|.\frac{D}{2}= \frac{m.D.(a + g.sin(\alpha))}{2}$

## Torque on motor shaft

Considering the gear box specifications gives us:

$\tau_{motor} = \frac {\tau_{wheel}}{R.\eta} = \frac{m.D.(a + g.sin(\alpha))}{2.R.\eta}$

## Power

The power produced by the motor is given by the product of the angular speed by the torque on the motor’s shaft. We can thus calculate the motor’s minimal power:

$P_{motor}=\omega_{wheel}.\tau_{motor}=\frac{m.v.(a + g.sin(\alpha))}{\eta}$