# Real-Time Robotics Framework

### Sidebar

getting_started:tutorials:oneaxis

# Control a Single Motor

This tutorial will show you how to control a single motor using EEROS. This example is located in a separate repository https://github.com/eeros-project/simple-motor-control.git.

## Theoretical Background

A motor position is measured by an encoder. After differentiating this signal we obtain the velocity. The input of the velocity controller is the difference between reference and measured velocity. Additionally, the feed forward velocity is added. The output of this controller is an acceleration. This value is then multiplied by the inertia and divided by the motor constant, in order to obtain a current reference value to control the motor.

Control loop

For a good dynamical stiffness we choose f0 = fs / 20 where fs is the sampling frequency. With fs = 1kHz we get f0 = 50Hz. With ω0 = 2·π·f0 the parameters for the position and velocity controller, kp and kv respectively, will be as follows:

kp = ω0 / 2·D and kv = 2·D·ω0

D is the damping factor and we choose it as 0.9.

## Experimental Setup

The motor we use has the following properties:

 Value Unit Properties 9.49 kgm2 16.3 10-3 Nm/A 500

We use three different platforms for running the Simple Motor Controller.

## Build Application

1. Download EEROS, hardware wrapper libraries, and simple motor application described in Installation and Setup. Make sure that the following entry in config.sh.in is as follows
use_custom_application=true
2. After cloning with the clone script, navigate to the directory simple-motor-control where you can find the code of the application.
3. Compile together with the application.
4. Deploy to the target system if necessary.

## Test Application

You will find different hardware configuration files depending on the hardware platform.

• HwConfigComedi.json
• HwConfigBBB.json

Start our application by choosing the appropriate configuration file, e.g.:

\$ sudo ./simpleMotorControl -c HwConfigBBB.json

The application logs the motor position once per second. By activating the emergency button, the safety system will immediately switch to an emergency state. Deactivating this button causes the system to switch back to running mode.

## Develop your own Application Further

For further development we recommend to use an integrated development environment as described in Say Hello with EEROS. You do not have to create a new project, because you already have downloaded and built the simple motor controller project. Hence, you import the project together with the EEROS and wrapper libraries into KDevelop as described in Use KDevelop with Existing Build Configuration.

## Implementation

### Control System

The control system declares in ControlSystem.hpp all the necessary blocks as given in the picture at the top of this page. Those blocks are then defined in ControlSystem.cpp, connected together, and added to a time domain. At last the time domain is added to the executor.

### Safety System

Safety levels and events are declared in SMCSafetyProperties.hpp. SMCSafetyProperties.cpp initializes these objects, defines critical inputs and outputs, defines level actions, and adds the levels to the safety system. The levels and events causing transitions between those levels are shown in the next figure.

Safety levels and events

Two critical inputs are defined: “emergency” and “readySig1”. “enable” is a critical output. Critical inputs and outputs are checked and set by each safety level. For example “enable” is set to true as soon as the safety level is equal or higher than powerOn. “emergency” is unchecked for the two lowest levels and leads to level change to level emergency for higher levels.

### Sequencer

The sequencer runs a sequence which turns the motor each second a tenth of a full turn.

getting_started/tutorials/oneaxis.txt · Last modified: 2019/10/15 12:27 by graf