Assignment 3: Threading, Synchronisation and Data Integrity
General Information
Intent: Skills in utilising, classes, abstraction, data structures, threading, data synchronisation and documentation will be assessed.
Individual Task
Weight: 20%
Task: Write a program in C++ using object oriented paradigms that shares data originating from a range of Mechatronics sensors between a number of threads. Ensure data integrity between threads and enable relating data between them via suitable data structure that enables time synchronisation and subsequently interpolation of data for task at hand. Supply appropriate auto-generated documentation utilising inline source mark-up.
Rationale: In a Mechatronics System, sensors produce data at varying rates. Decisions need to be made based on correctly associated data in near real-time. Threading and synchronisation are ways to ensure the system performs as intended, with guarantees on the responsiveness of the system to incoming data changes, processing constraints and system behaviour.
Your task is to (a) create a number of threads that can handle buffering incoming data in an agnostic manner (b) create a separate thread to process the data from the sensors that ensures synchronisation of the data between producers / consumers and produces an output by extrapolation of data (extrapolation is the process of estimating, beyond the original observation).
Due: As per subject outline
Revision Date
Change
04-Sep-2019
Updated max speed
Specifics
An aircraft is patrolling space surrounding a base station. The aircrafts task is to localise an enemy aircraft (bogie) that enters the airspace and intercept the aircraft by shadowing it (keeping on top of it) for a period of time.
The aircraft is controlled by supplying desired linear velocity and angular velocity (V and ω) that the on-board systems immediately respond to, as long as they are within operational parameters of aircraft. The controlled linear velocity cannot be less than a terminal velocity (50 m/s), otherwise the aircraft will stall and fall from the sky, or above max velocity (900 m/s). The combination of linear and angular velocity cannot exceed 6G (safety limit for the pilot : calculated as V *
ω / g ; g being gravitational force). A watchdog timer in the control systems monitors that control input is supplied every 50ms (5ms tolerance), i f this is not met the control system will fail.
The aircraft is equipment with:
A high-precision INSGPS that provides the aircraft precise pose (x,y and θ)
An omnidirectional radar that provides range to the bogie (from the
aircraft) updating at 100Hz
Apart from the on-board Radar the aircraft can:
Receive readings from a radar situated at the base station that provides range to the bogie (from the base station) at 10Hz (the base station is at location x= 0 y=0).
A library (libsimulator.a) and header files encompassing the simulator is provided (as part of skeleton code – details below).
To illustrate how to use the simulator a sample project containing: CMakeLists.txt and simple main exploiting the simulator is available under student git repository (skeleton/a3_skeleton).
The complete API for the Simulator is available under your git repository (skeleton/a3_simulator_doc). To access the API specifics, open index.html within above noted folder (for instance “firefox index.html”). Peruse Class List and view the methods available under Simulator class.
Task
Create an instance of the simulation and a number of threads to achieve control of an aircraft with an aim of (1) estimating the position of an enemy aircraft (bogie) and (2) shadowing this aircraft : keeping the aircraft on top of the bogie (within 600m) for 2 seconds.
Your system will need to
1. Obtain radar data from the aircraft and the ground station
2. Utilise the radar data to estimate the bogie position (via intersect of the
ranges – circles) and display the estimated position on the simulator
3. Linearly extrapolate the bogie position (determine what parameters are
needed for this task)
4. Estimate a control action that will lead to your aircraft intercepting the
bogie
5. Control the aircraft within the watchdog imposed limits and aircraft
specification envelope (terminal velocity / max velocity / max G profile).
6. Continue to determine control actions that will allow you to shadow the
bogie
Therefore, you will need to design classes mapped to the task and functionality (refer assessment criteria).
The Main will
1. Creates objects from your classes
2. Creates a suitable number of threads for the task
3. Handle concurrency using appropriate data protection 4. Achieves goals (1-6)
5. Wait until the program is terminated with CTRL+C
Figure 1 – Simulator, aircraft (red), bogie and path taken by bogie over last second (green) , base station (black), airspace (light blue)
Figure 2 – Details of the range obtained relative to base station and bogie, the unknowns are bogie specifics.
Assessment Criteria Specifics
Criteria
%
Description / Evidence
Use of appropriate data structures, locking mechanisms, data sorting mechanisms
Total weight (%) 40
Design adheres to principles of: Inheritance from base class, common data stored and generic functionality implemented solely in base class (no duplication). Member variables/functions that should not be available for instantiation aptly protected.
Suitable data containers, sorting mechanisms optimal with respect to memory footprint.
Use of synchronisation mechanisms to enable efficient multithreading and safe data sharing between threads (avoiding busy waits / optimise locking).
20
Correct use of access specifier
20
Constructors available and used correctly
10
STL container used to track all possible locations of bogie
10
STL container used for task of time sync
5
STL containers used for task of range sync
10
STL used to determine velocity/orientation of bogie
10
Threading implemented so no loss of sensor data
10
Use of mutexes makes data secured
5
Use of convars allows asynchronous operation
10
Base class and derived class are well thought out (BONUS PTS)
Proper code execution
Total weight (%) 30
Range data fused (extrapolated/interpolated) and combined with aircraft location to correctly estimate bogie position.
Aircraft controlled in specified watchdog timer intervals within limits of aircraft specification envelope (terminal velocity / max G profile).
Range data fused (extrapolated/interpolated) and combined with aircraft and bogie pose/velocity/angular velocity data to shadow the bogie for time specified.
10
Correct location of bogie (one of two locations)
5
Correct orientation of bogie produced
5
Aircraft controlled with point ahead of current bogie pose
30
Aircraft controlled such that watchdog timer does not elapse
20
Aircraft controlled so it remains in airspace
20
Bogie shadowed successfully once (intentional and confirmed by simulator)
10
Bogie shadowed repeatedly
Documentation Total weight (%) 10
10 0
Documentation is produced via Doxygen.
All source files contain useful comments to
understand methods, members and inner
workings (ie extrapolation, control method).
For HD a landing page (cover page) must be provided with decription of submission.
Modularity of software
Total weight (%) 20
Appropriate use class declarations, definitions, default values and naming convention allowing for reuse.
No implicit coupling between classes that
disables reuse.
All classes interface in ways allowing use of class in others contexts and expansion (ie controlling another aircraft to pursue bogie, adding another radar into computation of bogie pose).
No “hard coded” values or assumptions.
30
Classes designed such that they have sole responsibility to allow reuse
10
Main connects objects and threading
5
Constants are in appropriate locations to allow change
20
No repeated segments of code that performs same operations
5
Locking mechanism embedded with data
10
Locking mechanisms are activated via function paired with data
15
Separate threads running control of aircraft and computations of control actions
5
The computation of the bogie pose could be extended with more radar information
FAQ
What are Radar range limits?
Range of detection 0 to ∞ (infinity)
What is orientation reported in?
Radians, orientation is reported 0 – 2π
Should my assignment have any other classes (header and implementation files)
ABSOLUTELY, your main should only setup the threads and setup passing between them.
All other implementation should be in classes
How do students generate Doxygen for their assignment
A complete introduction to doxygen is provided on UTSOnline as well as a sample project in week 5.
If you wish solely to exploit in text commenting (without project files, which suffices for marking) then a quick way is to execute following two commands within your project folder:
1. “doxygen –g” (which will generate Doxyfile) 2. “doxygen Doxyfile”(generates the html and
latex)
DO NOT submit the generated document files as part of your ZIP, we can generate them from your source files.
How to control aircraft / get range
The simulator class provides access to all the data and control utilities of your aircraft, please view example main.cpp.
Students are at liberty to use the other classes and structs available for your work (for instance create an aircraft struct and populate readings)
I can’t compile the sample code, cmake fails on OpenCVConfig.cmake
If your running A3 (skeleton code) on your own device (your not using the VM or FEIT Linux labs) you will need to have Ubuntu 16.04 LTS and ROS Kinetic (or 18.04 LTS and ROS Melodic). You will need ROS for individual projects (A5).
DO NOT install OpenCV directly from OpenCV website, it is part of ROS!
Follow all steps on following link to install ROS (kinetic on 16.04 OR melodic on 18.04) http://wiki.ros.org/kinetic/Installation/Ubuntu