-
Notifications
You must be signed in to change notification settings - Fork 16
BicopShield
Introduction
Application programming interface
C/C++ API
Simulink API
Examples
Identification
Feedback control
State estimation
Detailed hardware description
Circuit design
Parts
PCB
About
The BicopShield belongs to the family of control engineering education devices for Arduino that form a part of the AutomationShield project.
The BicopShield is based on an Arduino development board with a standard R3 pinout. The device itself is then built on top of a custom PCB with the rest of the electronic and mechanical components attached to it. The moving part consists of a square and horizontal round carbon rod, connected with a 3D-printed mount, on which is a 3D printed holder for the BoB module. The small coreless DC motors, commonly used for miniature drones, with a propellers, is mounted to the ends of a square rod through a 3D-printed motor connector. The horizontal round rod is seated between two plastic bearings. At the end of this rod is a magnet attached to it in a 3D-printed holder. As the sensor, a Hall-effect rotational encoder is located behind the ball bearing in the axis of its rotational movement on a custom breakout PCB. The whole assembly is connected to the 3D-printed main body mounted on the PCB. The device represents a simple system with two inputs and one output, where the goal is to control the angle of inclination of the pendulum by changing the lift created by the motors.
The 3D printed parts are available for download here.
The application programming interface (API) serving the device is written in C/C++ and is integrated into the open-source AutomationShield Arduino library. This library includes header files for all available devices from the AutomationShield family. The BicopShield.h
header file contains the forward declaration of the BicopClass
for hardware interface methods. An BicopShield
object is initialized from within this header. After including the header, the system can be simply started by calling the
BicopShield.begin();
method launching the I2C interface and starting the magnetic encoder itself. This method also provides information about the sensor's functionality by detecting the magnet and printing to the serial port whether the magnet can be sensed or not. When using BicopShield with BoB extension, for its initialization call BicopShield.TOFinitialize();
method.
After initializing the shield, the calibration procedure is called by
BicopShield.calibrate();
,
and for calibration of time of flight sensor on the BoB module is used
BicopShield.TOFcalibration();
.
The angular displacement of the pendulum is read by
y=BicopShield.sensorRead();
returning the raw angle reading, which is then mapped to an angle value in the range of 0-360°.
The position of the ball is read by
y=AeroShield.TOFreadRead();
which provides actual position of the ball in mm.
By supplying the input u1
and u2
in the range of 0-100% to the
BicopShield.actuatorWrite(u1,u2);
method, the user can control the speed of the motors respectively. This method also constrains the output value to avoid overflow and maps the input to an 8-bit PWM integer. The output of this method is then sent to the Arduino pin D5 and D6, which are used to deliver the PWM signal to the PCB circuitry.
Finally, a reference angle set by the user is acquired from the potentiometer by calling
r=BicopShield.referenceRead();
which returns the position of the potentiometer runner as a floating point scaled to 0-100%.
Intuitive tool for creating control loops and perform live experiments is the Simulink API for the BicopShield. It utilizes the Simulink Support Package for Arduino Hardware which supplies algorithmic units in blocks that access the core hardware functionality.
All necessary functions of the BicopShield are built into separate blocks available for use through the BicopLibrary (see figure below) and may be combined with all the other available blocks to create feedback control applications.
The Simulink API custom library retains the naming convention and features for individual input and output blocks Reference Read
, Actuator Write Motor1
, Actuator Write Motor2
and Angle Read
and a comprehensive block representing the entire device BicopShield
.
When using this library and arduino package, code is run directly on the microcontroller. Simulink not only transcribes the block schemes for hardware, it also maintains the connection between the development computer and MCU. This way controllers can be fine-tuned in a live session, or data may be displayed and logged conveniently.
BicopShield represents a double-input single-output system, where the manipulated inputs is the voltages of the motors (in %),
where
The worked example BicopShield_Ident.m
takes the experimental data and searches for the unknown parameters of the first-principle model.
The input-output data for system identification were obtained from PID example. The unknown parameters are then found by a grey-box estimation procedure utilizing an appropriate search method implemented in MATLAB's System Identification Toolbox. The resulting models provide a very good match to the measured data as indicated in the figure below.
The following sample examples were implemented in both Arduino IDE and Simulink API. Let us start with PID control, since it most certainly forms an important part of any fundamental control course. The discrete PID controller assumed in this demonstration was hand-tuned. The figure below shows the result of its real-time implementation in Arduino IDE with the help of API, plotted in MATLAB. The arm tracks the desired angle reference, set automatically using predefined reference trajectory, swiftly and accurately. The example uses the PID framework from Automation-Shield to aid the learning progress of beginners even more.
Another example demonstrates the state-feedback control, linear-quadratic regulator (LQR) compared with explicit model predictive regulator (EMPC). To design it, we used the state-space model obtained from the identification example. The controller was implemented using C/C++ API, assuming calculation of angular velocity from position measurements via a finite difference method. The resulting control performances of both are beyond sufficient. As shown in figure below, the EMPC is way better.
Kalman filter was used for state estimation in the examples with LQ and EMPC control. For LQ, the Kalman filter was used in the Simulink API and for EMPC control in the C/C++ API. It was also used to verify the identified model, where it follows the trajectory of the measured data well, while it has a smoother behavior.
Previous figure detailed:
The BicopShield is an open hardware product, you are free to make your own device. If you come up with improvements, please let us know so we can improve our design as well. The discussion below should help you to improvise a similar setup for experimentation on a breadboard or perforation board. You may even order a professionally made PCB by a PCB fabrication service.
Following the electronic schematics, the voltage for the motors M1 and M2 is supplied from an external source through the barrel jack connector on the Arduino board, while the power supplied to motor is controlled by the low-side MOSFET transistors Q1 and Q2 which receives a PWM signal from Arduino pin D5 and D6 through the current limiting resistors. Floating states are handled by a 10kΩ pull-down resistors R9 and R10, while a diodes D2 and D3 ensures back electromotive-force (EMF) protection. Operating voltage of the motor is 3.7V, hence a buck-down converter U1 steps down the voltage. The magnetic encoder is integrated into the breakout PCB with two capacitors, and connected to the I2C bus connectors of the Arduino (SDA, SCL). Finally, there is a potentiometer POT1 with a small plastic shaft that may be used to manually set the desired reference angle signal. The electronic schematics was designed in the free version of DIPTrace. You may download the circuit schematics of the BicopShield from here.
To make an BicopShield either on a PCB or on a breadboard you will need the following parts or their similar equivalents:
part | name | Type/Value/Note | PCS |
---|---|---|---|
a), b) | BicopShield body | 3D printed | 2 |
g) | Motor | High-speed DC coreless motor 7mm×15mm, 3.7V, 1mm shaft | 2 |
g) | Propeller | 4-blade propeller with ∅30mm | 2 |
m) | Magnetic encoder | AS5600, 12-bit on-axis magnetic rotary position sensor | 1 |
i) | BoB extension | 1 | |
Disc magnet | ∅6mm, 2.5mm thick | 1 | |
k) | Plastic ball bearings | IGUS BB-694-B180-30-ES | 2 |
j) | Carbon rod | circular cross-section ∅ 4mm ×∅ 3mm | 1 |
h) | Carbon rod | square cross-section, 4mm × 3mm | 1 |
c),d),e),f),l) | 3D printed parts | 4 | |
U1 | Buck converter | TPS56339, 3A output synchronous buck converter | 1 |
C1,C5,C6,C7 | Capacitor | 0.1µF | 4 |
C2, C3 | Capacitor | 22µF | 2 |
C4 | Capacitor | 10µF | 1 |
D2, D3 | Diode | 1N4001 DO-214, 50V, 1A | 2 |
D1 | Diode | Zener diode BZT52C8V2-7-F | 1 |
J1 | Connector | 280371-1, 4-pin | 2 |
M1, M2 | Connector | 280370-1, 2-pin | 2 |
L1 | Inductor | 0.1μH DR73-1R5-R | 1 |
POT1 | Potentiometer | 10kΩ ca14 | 1 |
Q1, Q2 | MOSFET | PMW45EN2, 30V, N-channel trench MOSFET | 2 |
R1, R5, R9, R10 | Resistor | 10k RES0805L | 4 |
R2, R3 | Resistor | 100R RES0805L | 2 |
R6, R7 | Resistor | 4,7k RES0805L | 2 |
R4 | Resistor | 52,3k 1% RES0805L | 1 |
R8 | Resistor | 10k 1% RES0805L | 1 |
Cables (motor) | 4 | ||
FFC cables | 4-pin, min 2x15cm | 2 | |
Connector | 280371-1 | 2 | |
Connector | 280358 | 2 | |
Screws | 4 pcs. M3×10, 10 pcs. M2x8 | 14 | |
Nuts | M2 | 5 |
Note that the total cost of the above components and thus of the entire BicopShield is no more than 40€ excluding labor, postage and soldering material. Excluding BoB extension total cost is no more than 35€
The printed circuit board was also designed in the freeware version of the DIPTrace CAD software. The PCB is two-layer. The DIPTrace PCB layout and circuit schematics can be downloaded here, while the ready-to-manufacture Gerber files with the NC drilling instructions are available from here.
The assembled shield is fixed mechanically and electrically to the Arduino board through stackable header pins. The location of the components is also illustrated in the PCB layout below. The pendulum body is attached through 4 pre-drilled holes made in the manufacturing process.
This shield was designed and created as a master's thesis at the Institute of Automation, Informatization, and Measurement. The Institute belongs to the Faculty of Mechanical Engineering, Slovak University of Technology in Bratislava in 2023/2024.
Takács et al., 2018-2023. The hardware design, software and manual featured in this repository is licensed under a Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0). Please consider citing our work in your publication.