I am currently creating a robot to which some sensors are attached. The robot control unit is ARM Cortex-M3, all sensors are connected to it, and it is connected via Ethernet to the โground stationโ.
Now I want to read and write settings on the robot through a ground station. So I thought about introducing a "virtual register" on a robot that can be manipulated by a ground station.
It can consist of structures and look like this:
// accelerometer register struct accel_reg { // accelerations int32_t accelX; int32_t accelY; int32_t accelZ; }; // infrared distance sensor register struct ir_reg { uint16_t dist; // distance }; // robot register table struct { uint8_t status; // current state uint32_t faultFlags; // some fault flags accel_reg accelerometer; // accelerometer register ir_reg ir_sensors[4]; // 4 IR sensors connected } robot; // usage example: robot.accelerometer.accelX = -981; robot.ir_sensors[1].dist = 1024;
On the robot, the registers will be constantly filled with new values, and configuration settings are set by the ground station and applied by the robot.
The ground station and the robot will be written in C ++ so that both of them can use the same type of structure structure.
Question I have a question about how to encapsulate read / write operations in a protocol without writing a lot of metadata?
Let's say I want to read the robot.ir_sensors[2].dist . How can I access this register in my protocol?
I already thought about transmitting the relative offset in bytes (i.e. the relative position in the memory inside the structure), but I think that aligning and adding memory can cause problems, especially because the ground station runs on x86_64 architecture, and the robot runs on 32-bit ARM processor.
Thanks for any tips! :)
source share