..
2. Connect STM to CM via SPI when using IO board. On car’s board it is connected already...
3. Copy bootloader stm32boot to RPi (You can find it in slotcar-fs.git/car-fs/slotcar/stm32boot)...
4. Run "/slotcar/stm32boot -p path_to_bin.bin 0x08000000".4.6 Linux command line commands
Slotcar. First script is used for maintaining the car. the help of the script is self explaining.
/bin/bash /slotcar/slotcar.sh
Usage: /slotcar/slotcar.sh {COMMAND} arg1 arg2 ...
COMMANDS:
mro Makes / and /boot read-only.
mrw Makes / and /boot read-write.
start Starts the slotcar application.
stop Stops the slotcar application.
status Shows status of the slotcar application.
log Shows the log of the slotcar application.
addr Returns (and sets if {arg1} is set) the address of the slotcar.
{arg1} must be a number.
upgrade Upgrades slotcar’s file-system from Git.
stm Subscript for maintaining the STM.
For more information write ’stm help’.
ntp Sets ntp server.
{arg1} is the IP address of the server.
help Shows this message.
STM. Another script is a subscript of the previous one. This script particu-larly controls STM only. Again we show its call and help.
/bin/bash /slotcar/slotcar.sh stm Usage: stm {COMMAND}
COMMANDS:
program, p Program STM flash.
Source file is "/slotcar/slotcar_stm.bin".
start Starts STM program.
stop Stops STM program.
restart Restarts STM program.
help, h Display this message.
4. Beginning with the platform
...
Standalone STM loader. As was mentioned, we created a STM loader which a standalone application.
/slotcar/stm32boot -p /slotcar/slotcar_stm.bin 0x08000000
Bash aliases. The most used commands has been added into aliases (see listing 4.1).
Listing 4.1: Bash Command line aliases.
SLOTCAR_SH =’/ bin / bash / slotcar / slotcar .sh ’ alias l=’/ bin /ls -al ’
alias mro =’ $SLOTCAR_SH mro ’ alias mrw =’ $SLOTCAR_SH mrw ’ alias start =’ $SLOTCAR_SH start ’ alias stop =’ $SLOTCAR_SH stop ’
alias restart =’ $SLOTCAR_SH restart ’ alias status =’ $SLOTCAR_SH status ’ alias log =’ $SLOTCAR_SH log ’
alias addr =’ $SLOTCAR_SH addr ’ alias stm =’ $SLOTCAR_SH stm ’
Chapter 5
Model
The vehicle is modeled as a loaded brush-type permanent magnet DC motor connected to the wheels through the gear train. The rotation of the wheels produces a force that pushes the car. The force is proportional to the torque of the wheels and also to the torque of the motor because we neglect slipping of the wheels and we consider the gear train as ideal. The car alone is represented by mass with weight m. The equations can be written down almost immediately using the bond graph in Fig. 5.1
di(t)
dt = u(t) L −R
Li(t) − k
rnLv(t), (5.1)
dv(t) dt = k
mnri(t) − Ff(v)
m , (5.2)
dx(t)
dt = v(t). (5.3)
The states are: the electrical current i flowing through the motor winding (in A), the velocity v of the car (in m s−1), and the traveled distance x (in m).
Se: u 1i
I1: L R1: R
G: k T : n T : r 1v I: m
R: Ff(v)
Figure 5.1: Bond graph of the one-dimensional electromechanical dynamics of a slot-car as a loaded permanent magnet DC motor with a permanent magnet.
The control input is the voltage u (in V). In reality, the input voltage comes in the Pulse Width Modulated (PWM) signal of frequency 40 kHz with the duty cycle Dc, where Dc∈[−1, 1]. Hence u(t) = UrDc(t) denotes just
5. Model
...
the low-frequency content, where Ur 1 (in V) is the rail voltage lowered by the input diode voltage (0.8V). The model has one significant non-linearity and it is the static friction. The friction force
Ff(v(t)) = bdv(t) + bssign(v(t))
applied on the car has two parts static and dynamic, where coefficient bd is the dynamical (viscous) friction and bs is the static friction2. The relevant physical parameters are in Table 5.1.
Physical parameter Symbol Value Unit
Resistance of the motor winding R 8 Ω Inductance of the motor winding L 2 mH
Torque constant k 0.006 N m A−1
Mass of the slot car m 0.15 kg
Dynamic friction coefficient bd 0.27 kg s−1 Static friction coefficient bs 0.53 N
Radius of the wheel r 0.01 m
Gear train ratio n 1/3
Table 5.1: Parameters for the vehicle model.
We implemented the full non-linear model in MATLAB Simulink, see Fig 5.4, which is used for simulations. We can see in the figure 5.2 a comparison of the simulation and the reality. The input for this test was the PWM duty cycle from 0.1% to 0.5%. We can see that velocity and of course the back EMF (from which the velocity is calculated) fit. Therefore the model of non-linear friction is accurate. It needs to be noted, that it only works once the wheels are rotating as you can also see from the figure. It turns out that the model of static friction is more complicated when starting from zero velocity, because on the way up 0.1% was not enough to move the wheels and it was enough on the way down; it has a hysteresis.
5.1 Linearization
Note that while the linear model turns out nearly perfect for most aspects here, it fails badly when describing the friction phenomenon. Here the friction comes from three sources—friction induced by the angular motion of the rotor shaft, friction in the slot, and the rolling friction. It is well known that the rolling friction does not depend on the velocity but only depends
1The input (rail) voltage is not stabilized, therefore it can vary along the track because of changes in electrical resistance, although not much. It is good to make a dummy ride before running a comparison experiment just to find out how the voltage varies and then put the mean into the model.
2The model of friction is simplified; it is not correct for velocities around zero. For a better estimation of the friction, the Karnopp model should be used.
...
5.1. LinearizationFigure 5.2: Car model: the reality compared to the simulation. In this case the car is lifted and the wheels are rotating in the air. Therefore the coefficients are different m = 0.01, bd= 0.01, bs= 0.09.
on the normal force (here it is not only the weight but also the attractive force of magnets that push the slot car against the track). Introducing some nonlinearity into the model seems inevitable. But temporarily, the linear model of a friction is used to get a transfer function as rough models of the overall dynamics.
The electric current dynamics is very fast compared to the mechanical dynamics of the velocity, so we can neglect it by setting di(t)dt = 0 in (5.1).
Separating i(t) and plugging it to (5.2), we get dv(t)
Transfer functions from the input voltage are
G(s) = v(s)
5. Model
...
4 6 8 10 12 14 16 18 20
0 1 2 3
4 6 8 10 12 14 16 18 20
0 0.5 1
4 6 8 10 12 14 16 18 20
0 2 4
Figure 5.3: Car model: the reality compared to the simulation.
After plugging in the values of the parameters, G(s) = 3.2
0.3s + 1. (5.8)
In combination with a dead-zone on input, which represents the static friction, is the linear model good approximation of reality. The dead-zone is set to range [−0.30, 0.30]% of PWM duty cycle, which is needed to overcome the static friction.
...
5.1. LinearizationChapter 6
Control
We separate the control problem into (1) control of the velocity of the car and (2) control of the inter-vehicle distances. They are connected in the cascade structure, where the velocity control loop is the inner one and the distance control loop is the outer one, as seen in Fig.1.3.
6.1 Velocity control
The velocity measurement and the control loop is implemented in STM. The velocity controller is a standard discrete PI controller with following structure
Cv(z) = kp,v+ ki,v Ts,v
z −1, (6.1)
where kp,v = 2, ki,v= 10 and sampling period Ts,v = 0.005 s. The controller implements an anti-windup in a form of clamping [−1, 1]. The input control error ev = vref − v , where vref is reference velocity. The control effort is the PWM duty cycle Dc. The comparison of the simulation and the real implementation, Fig. 6.2, shows a good agreement in both, the velocity and the control effort.
For continuous analysis, we use the transfer function Cv(s) = 2s + 10
s . The bode diagram of the velocity loop is in Fig. 6.1.