This tutorial will show you how to control a single motor using EEROS. You can find the code in the directory with examples. Navigate to examples/simpleMotorController.
The motors position is measured by an encoder. After differentiating this signal we obtain the velocity.
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.
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.
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) deflivers the necessary power. The motor we use has the following properties:
|Motor Constant||16.3 10-3||Nm/A|
In the EEROS library you will find a directory with examples. Navigate to
You will find two different hardware configuration files.
Start our application by choosing the appropriate configuration file, e.g.:
$ ./simpleMotorController -c HalSimpleMotorControllerComedi.json
The control system declares in
MyControlSystem.hpp all the necessary blocks as given in the picture at the top of this page. Those blocks are then defined in
MyControlSystem.cpp, connected together, and added to a time domain. At last the time domain is added to the executor.
Safety levels and events are declared in
MySafetyProperties.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.
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.
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.