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.
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.
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 motor we use has the following properties:
|Motor Constant||16.3 10-3||Nm/A|
We use three different platforms for running the Simple Motor Controller.
config.sh.inis as follows
simple-motor-controlwhere you can find the code of the application.
You will find different hardware configuration files depending on the hardware platform.
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.
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.
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 levels and events are declared in
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.
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 each second a tenth of a full turn.