This project is a Production-Grade Robot Fleet Management System written in C. It is designed to simulate the backend infrastructure required to manage a fleet of autonomous warehouse robots. The system handles real-time data management, hardware-level status monitoring, and spatial collision avoidance.
- The system uses a dynamic array of robot structures.
- It utilizes
malloc,realloc, andfreeto scale the fleet size at runtime. -
Optimization: Deletions are handled via
memmoveto shift memory in$O(1)$ allocation cycles, followed by a single hardware-levelreallocto shrink the array, preventing memory thrashing.
- Struct Packing: Uses
__attribute__((__packed__))to eliminate compiler-injected padding. This ensures the binary data is consistent across different CPU architectures (e.g., x86 vs. ARM). - Bitwise Status Monitoring: Uses a
uint8_tbitmask to store and toggle hardware states (Engine, Lights, Alarms) in a single byte of memory.
- Replaced a standard
$O(N^2)$ brute-force distance check with an Amortized$O(N)$ Spatial Hash Map. - The warehouse is mathematically divided into a grid. Robots are mapped to "buckets" based on their
$(X, Y)$ coordinates. - Collision Detection: The system only calculates distances between robots sharing the same grid sector, drastically reducing CPU cycles as the fleet scales.
- Implements a custom binary file I/O system (
fleet_data.bin). - On boot, the system reads the fleet count and raw struct data directly into RAM.
- On shutdown, it flushes the current state back to the disk, ensuring full persistence between sessions.
- Fleet Report: Decodes bitwise hardware statuses into human-readable logs.
-
Modify Fleet: Allows for adding/deleting robots and toggling specific hardware bits via XOR (
^) operations. -
Deployment Sorter: Uses the standard library
qsortwith a custom comparator function to sort the fleet by battery level in$O(N \log N)$ time. - Emergency Protocol: A safety routine that identifies low-battery robots, forces their engines/lights OFF, turns their Alarms ON, and re-sorts the fleet for priority charging.
- Input Validation: Uses a custom
get_safe_intfunction to prevent buffer overflows and handle non-integer input gracefully. - Memory Safety: Includes explicit checks for
reallocfailures and ensures all allocated memory (including the spatial grid) is freed before the program exits or returns from functions. - Data Sanitation: Uses
strcspnto strip newline characters from user-entered strings, ensuring the binary save file remains clean.
- Clone the repository:
git clone https://github.com/Udith-Praveen/Robot-Fleet-Backend-System.git
- Navigate to the directory:
cd Robot-Fleet-Backend-System - Compile the multiple files using GCC:
gcc -o fleet_manager main.c Robot_fleet_manager.c
- Run the executable:
./fleet_manager