User Tools

Site Tools


getting_started:tutorials:oneaxis

This is an old revision of the document!


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. It will be downloaded and built automatically if you follow Getting the Sources with a Script.

Navigate to the directory simple-motor-control where you can find the code.

Theoretical Background

The motors position is measured by an encoder. After differentiating this signal we obtain the velocity.

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.

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.

Part 2: Experimental Setup

As a processing platform we use a regular PC (x86-64) together with a National Instrument card: PCIe - 6251 (M-Series). The card requires the comedi library together with the EEROS hardware wrapper, see Hardware Libraries. In any case you have to install comedi separately. As an alternative we use our cb20 controller board (http://wiki.ntb.ch/infoportal/embedded_systems/imx6/cb together with http://www.flink-project.ch and the appropriate EEROS hardware wrapper, see Hardware Libraries.
For both alternatives a maxon motor controller (50V / 5A) delivers the necessary power. The motor we use has the following properties:

Properties Value Unit
Inertia 9.49 kgm2
Motor Constant 16.3 10-3 Nm/A
Encoder Pulses 500

Part 3: Test Application

If have have installed and built EEROS as described in Installation and Setup and Compile, you already have the necessary libraries together with the application. If you use comedi navigate to the build directory of your simple motor control directory. If you use the cb20 board, follow the instruction in https://github.com/ntb-ch/cb20 to download the necessary files to the target.

You will find two different hardware configuration files.

  • HalComedi.json
  • HalFlink.json

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

$ ./simpleMotorControl -c HalComedi.json

Part 4: 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 several steps forward. After 20 seconds it will position the motor back to some base position and restart the process.

getting_started/tutorials/oneaxis.1570538743.txt.gz · Last modified: 2019/10/08 14:45 by graf