QUB-ASL / bzzz

Quadcopter with ESP32 and RaspberryPi
MIT License
7 stars 1 forks source link

RFC: Configuration sequence from RPi to ESP32 #159

Open alphaville opened 10 months ago

alphaville commented 10 months ago

The issue

We have currently hard-coded certain parameters in the ESP32 code. For example:

and there might be other such hard-coded values. It would be better to be able to configure them from the Pi.

Proposed solution

The Pi will send via the Serial an initialisation sequence. In particular, it will send out the message in JSON format

{"command": "initialisation"}

in a while loop until the ESP32 reads it and acknowledges it by replying

{"status": "initialisation"}

Then, the Raspberry Pi will send to the ESP one the following messages

Proceed

if the ESP should just proceed with the default parameters, the following command should be issued

{"command": "proceed"}

The ESP should then acknowledge this by sending back the message

{"status": "proceeding"}

Calibrate

The Pi can send the command to the ESP for it to calibrate the magnetometer

{"command": "calibrate" }

The ESP will then acknowledge the message by saying {"status": "calibrating"} and once it has calibrated the magnetometer it will say {"status": "calibration complete"}.

Set gains

The following command can be sent to set certain (fixed) values to any of the controller gains or other parameters

{
    "command": "set_gains",
    "gain_xy": 123.4,
    "gain_omega_xy": -5.67
}

Again, the ESP will acknowledge the receipt of the command with {"status": "setting gains"} and

{
   "status": "gains set by RPi",
    "gain_xy": 123.4,
    "gain_omega_xy": -5.67,
    "gain_omega_z": 1.0101,
    "other_parameter": 0.5
}

Arming

When the ESP is ready to arm, it should return the message:

{"status": "ready to arm"}

before it arms, it should inform the Pi by sayin

{"status": "arming"}

and when it arms, it should say

{"status": "armed"}

Assignment of trimmers

The Raspberry can assign the trimmers to any of the parameters of the ESP32. For example, this can look like this:

{
    "command": "trimmer assignment",
    "assignments": [
        {"vra": "gain_xy", "min": 0.0, "max": 25.0},
        {"vrb": "gain_omega_xy", "min": 0.0, "max": 0.15},
    ]
}

The ESP32 will acknowledge the receipt of the command with {"status": "assigning trimmers"} and then {"status": "trimmers assigned"} (perhaps with additional information on the exact assignment).

Completion of initialisation sequence

The initialisation sequence ends when the Pi sends {"command": "proceed"} (see above).

Let me hear your thoughts on this.

alphaville commented 8 months ago

@jamie-54 @pdavid747 @Yuanbwcx @Minanchi @Runway27 I haven't heard anything from you on this; @ejb-11 please have a look at this too.