Introduction
In the context of our real-time development project, we were tasked with designing and implementing various functionalities for a robot. The primary objective was to manage the robot’s different tasks efficiently and securely using synchronization tools such as mutexes and semaphores. This report provides an overview of the project, the challenges encountered, and the solutions implemented.
Project
The project involved developing several functionalities for a robot, including camera management, arena detection, and task synchronization. We used FreeRTOS to manage real-time tasks and ensure safe concurrent execution.
Project Functionalities
| Function Name | Behavior Description | Inputs | Outputs |
|---|---|---|---|
| Start server | Launch server. If it fails, display a message and stop the program, otherwise produce “server started”. | Event: Start Data: inputStream |
Event: Server started |
| Connect to monitor | Wait for “server started”, call AcceptClient and wait for “open socket”. If ok, produce “connection established”. | Event: Server started | Event: connection established |
| Process monitor message | Wait for “connection established”. While: Wait for message inputStream (Read). If message = open com robot -> open comRobot. If message = open camera -> open camera. If message = close camera -> close camera. | Event: connection established Data: Movement |
Event: Open comRobot Open camera Close camera Start robot start arena search start robot search |
| Establish connection | Wait for “server started”, call AcceptClient and wait for “open socket”. If yes, connection established. | Event: openSocket serverStarted |
Event: connectionMonitor |
| Set up communication | Wait for “open comRobot”. Set up communication with the robot. If communication is ok, post “messageToMonACK”, otherwise post “messageToMonNAC”. Update the robot com status. | Event: open comRobot Data: robot com status Message Post |
|
| Start Robot | Wait for “Start robot”. If “robot com status” is active, send start order and update “robot started”. | Event: open comRobot Data: robot com status |
Data: robot started |
| Move robot | Every 100ms, if “robot started” is true, read “movement” and send order, otherwise nothing. | Data: robot started | Order |
| Send message to monitor | Wait for “connection established”. While: Wait for messageToMon, send the message to the supervisor. End while. | Event: connection established Data: Outputstream |
|
| Read battery level | Every 500ms, if “robot started” is true, ask for battery level from the robot and post it for the monitor. Otherwise, nothing. | Data: robot started Data: Message Post |
|
| Open/close camera | Wait for “open camera” or “close camera”. Open or close the camera, send a message to the monitor, update “camera open”. | Open camera Close camera Event: Display image Data: “Camera open” |
|
| Display Image | Wait for “Display image”. Every 50ms, if “camera open” is true, take an image from the camera stream. If “display arena” = true then draw arena on the image. Post the image for the monitor. | Event: Display image Data: “Camera open” Data: Message Post |
|
| Search Arena | Wait for “start arena search”. If “camera open” is true: “camera open = false”. Take an image from the camera stream, analyze the image and draw the arena on it. Post it for the monitor. | Event: start arena search Data: Message Post display arena |
|
| Search Position | Wait for “start robot search”. If “camera open” is true: Take an image from the camera stream, analyze the image and draw the robot. Update “robot drawing”. | Event: start robot search Data: “camera open” Data: Robot drawing |

Existing Functionalities
Before diving into the new functionalities we implemented, it is important to note that several key functionalities were already established:
Server Functionality
The server functionality is responsible for handling communication between the robot and external systems. This includes receiving commands and sending status updates.
Monitor Connection
The connection with the monitor is established, enabling the robot to send real-time data and receive instructions from the monitoring system.
Robot Movement
The functionality to move the robot is already in place, allowing the robot to navigate its environment based on the commands received.
Battery Level Reading
Battery level reading involves monitoring the robot’s battery status to ensure it has sufficient power to perform its tasks. This ensures that the robot has sufficient power to perform its tasks and can alert the system if the battery level is low. By keeping track of the battery level, we can prevent unexpected shutdowns and ensure the robot operates efficiently.
Camera Management
Camera management involved several operations, such as opening, closing, and capturing images. We used mutexes to protect access to shared resources, such as the camera state and the camera object itself. Here is a code snippet illustrating the use of mutexes.
Arena Detection
For arena detection, we created a function that is called when the user presses a specific button. This function uses semaphores to synchronize execution and ensure that tasks are executed in the correct order.
Conclusion
This project allowed us to apply advanced real-time programming concepts, such as using mutexes and semaphores for task synchronization. We successfully implemented the required functionalities for the robot while ensuring safe concurrent execution. The challenges we encountered helped us better understand the importance of synchronization and resource management in multithreaded programming.