Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pxh shell] param show results don't match the actual values of INT32 params set over MAVLink #19274

Open
squizz617 opened this issue Mar 2, 2022 · 6 comments

Comments

@squizz617
Copy link
Contributor

Describe the bug
Hi.
When I set the value of an INT32 parameter over MAVLink, and then request the param list (also over MAVLink), it shows the value I've set. However, on the pxh shell, weird values are shown when I do param show SOME_PARAM.

To Reproduce
[Terminal 1] make px4_sitl_rtps gazebo -j4
[Terminal 2] download and run the PoC:

$ python3 poc/poc_px4_param.py
[*] (MAVLink) set param COM_OBL_RC_ACT := 5
name: COM_OBL_RC_ACT    value: 5
[*] (MAVLink) set param COM_OBL_ACT := 2
name: COM_OBL_ACT       value: 2

Back on [Terminal 1] check parameters

pxh> param show COM_OBL_RC_ACT                                        
Symbols: x = used, + = saved, * = unsaved
x + COM_OBL_RC_ACT [159,234] : 1084227584

 662/1429 parameters used.                                            
pxh> param show COM_OBL_ACT                                           
Symbols: x = used, + = saved, * = unsaved
x + COM_OBL_ACT [158,233] : 1073741824

 662/1429 parameters used. 

Expected behavior
pxh shell should show the values properly, i.e., COM_OBL_RC_ACT: 5, COM_OBL_ACT: 2. Not sure whether this simply is an representation error on the shell, or those weird values are actually assigned to those parameters.

Log Files and Screenshots
Flight review - Download > Parameters also shows the incorrect values:

COM_OBL_ACT, 1073741824
COM_OBL_RC_ACT, 1084227584

Drone (please complete the following information):

  • Build: px4_sitl_rtps
  • Commit: a2645418

Thank you!

@dagar
Copy link
Member

dagar commented Mar 2, 2022

Try it with a float, it's probably the encoding of the integer.

http://mavlink.io/en/messages/common.html#PARAM_SET

You need to put the actual byte representation of the integer into the value field, like if it were a union.

// According to the mavlink spec we should always acknowledge a write operation.
param_set(param, &(set.param_value));

@squizz617
Copy link
Contributor Author

squizz617 commented Mar 2, 2022

Thanks for the quick feedback @dagar.

Try it with a float, it's probably the encoding of the integer.

Both COM_BOL_RC_ACT and COM_OBL_ACT are INT32 parameters, and the attempts to set it as FLOAT are rejected by PX4. I've already fiddled with a few different parameters, and confirmed that the param change is only accepted when the type is set as INT32 (MAV_PARAM_TYPE_INT32 to be exact).

You need to put the actual byte representation of the integer into the value field

I believe the encoding is already handled by pymavlink's param_set_send API as shown in the PoC above, isn't it? For FLOAT parameters, param setting over MAVLink shows consistent values in both pxh shell and over MAVLink.

@dagar
Copy link
Member

dagar commented Mar 2, 2022

Both COM_BOL_RC_ACT and COM_OBL_ACT are INT32 parameters, and the attempts to set it as FLOAT are rejected by PX4.

I'm saying try setting an actual float parameter with a float value to validate if the rest is otherwise working.

I believe the encoding is already handled by pymavlink's param_set_send API as shown in the PoC above, isn't it? For FLOAT parameters, param setting over MAVLink shows consistent values in both pxh shell and over MAVLink.

I don't know, we'd have to dig into pymavlink source (it's a completely separate project). Some mavlink specific details here, but things evolved differently over the years due to ambiguity. http://mavlink.io/en/services/parameter.html#px4

@squizz617
Copy link
Contributor Author

I'm saying try setting an actual float parameter with a float value

I see. I've confirmed that it works without any issue with the float parameters.

As you said, it seems like the issue could be on the pymavlink side. I'll talk to them. Thanks!

@dagar
Copy link
Member

dagar commented Mar 2, 2022

FYI @hamishwillee

@damien-robotsix
Copy link
Contributor

damien-robotsix commented May 16, 2024

I still have the same issue. Some years later. Does anyone have any feedback on this? Setting parameters from pymavlink (int32) still doesn't work properly.

For the record, I found a workaround making the conversion manually before calling the pymavlink interface. For example (unsing import struct), but well, I guess it would be nicer if the conversion was made by the pymavlink module :):

packed = struct.pack("i", value)
value_f = struct.unpack("f", packed)[0]
# Send parameter set command
connection.param_set_send(
    param, value_f, mavutil.mavlink.MAV_PARAM_TYPE_INT32
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants