Mavros: Setting PX4 parameters using MAVROS

Created on 31 Aug 2017  ·  10Comments  ·  Source: mavlink/mavros

Hi

I am trying to change some parameters on a PX4 flight stack using MAVROS.

I am able to read the parameter with mavros using
rosservice call /mavros/param/get MPC_LAND_SPEED

however I am not able to set it using mavros. I do not know what he correct syntax is

I tried
rosservice call /mavros/param/set MPC_LAND_SPEED '0.4'
however it gives me an error. If anyone can help I would be very grateful!

Thank you

Sebastian

question

Most helpful comment

It is because you are trying to call the set method via a service.

Via a service, the ROS way is:

rosservice call /param/set "param_id: 'MPC_LAND_SPEED'
value:
  integer: 0
  real: 0.4" 

All 10 comments

Does you tried mavparam script? rosrun mavros mavparam set MPC_LAND_SPEED 0.4?

It is because you are trying to call the set method via a service.

Via a service, the ROS way is:

rosservice call /param/set "param_id: 'MPC_LAND_SPEED'
value:
  integer: 0
  real: 0.4" 

Seem you have two working options @shening. Closing

It is because you are trying to call the set method via a service.

Via a service, the ROS way is:
rosservice call /param/set "param_id: 'MPC_LAND_SPEED'
value:
integer: 0
real: 0.4"

From the help of the above method, more exact method is described here.

The above command makes an error in my trial. But it worked after a blank space was added before 'integer' and 'real'. And '/mavros' added as like:

rosservice call /mavros/param/set "param_id: 'SENS_EN_THERMAL'
value:
  integer: 55
  real: 0.0"

cf) In this comment editor, a blank space can be added by writing   instead of ' '(space).

@bigbellmercy Is this issue apparent only in command line arguments? or is this also true when you use rosservice calls over roscpp?

@bigbellmercy Indeed, that was 3 years ago and the space was not obvious, I just added ``` around it and now it is obvious. The typical way I use rosservice it is to make abusive use of to prevent typos :laughing:

@bigbellmercy Is this issue apparent only in command line arguments? or is this also true when you use rosservice calls over roscpp?

@Jaeyoung-Lim I failed to 'rosservice calls over roscpp' using the command lines above.

But the below code works for PX4 parameter change in roscpp:

system("rosrun mavros mavparam set SENS_EN_THERMAL 55");

@Jaeyoung-Lim I meant roscpp by using the ros service calls, not using command line arguments

@Jaeyoung-Lim I couldn't find the solution for it in my trials.

Using roscpp service calls, I was also unable to directly get or set a PX4 parameter. I always got the following error:

[/mavros:std_plugins::ParamPlugin::get_cb]: PR: Unknown parameter to get: MPC_XY_VEL_MAX
[/mavros:std_plugins::ParamPlugin::set_cb]: PR: Unknown parameter to set: MPC_XY_VEL_MAX

Is there some prefix to add to the parameter ID?

It worked without problems using the mavparam script:
rosrun mavros mavparam -n /mavros get MPC_XY_VEL_MAX

However, I want to do it programmatically. I found a workaround by pulling the parameters to ROS, making the desired changes, and then pushing them all back:

ServiceClient pull_client = nh.serviceClient<mavros_msgs::ParamPull>("mavros/param/pull");
pull_client.waitForExistence();
mavros_msgs::ParamPull pull;
if (pull_client.call(pull)) {
    if (pull.response.success) {
        ROS_DEBUG("Pulled %d parameters from FCU", pull.response.param_received);
        nh.setParam("mavros/param/MPC_XY_VEL_MAX", max_velocity);
        ServiceClient push_client = nh.serviceClient<mavros_msgs::ParamPush>("mavros/param/push");
        push_client.waitForExistence();
        mavros_msgs::ParamPush push;
        if (push_client.call(push)) {
            if (push.response.success)
                ROS_DEBUG("Pushed %d parameters to FCU", push.response.param_transfered);
            else
                ROS_ERROR("Failed push parameters to FCU, cannot set maximum horizontal velocity!");
        }
        else {
            ROS_ERROR("Failed to push parameters to FCU, cannot set maximum horizontal velocity!");
        }
    }
    else {
        ROS_ERROR("Failed to pull parameters from FCU, cannot set maximum horizontal velocity!");
    }
}
else {
    ROS_ERROR("Failed to pull parameters from FCU, cannot set maximum horizontal velocity!");
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Phadadev picture Phadadev  ·  4Comments

MasterRos picture MasterRos  ·  12Comments

mohand150 picture mohand150  ·  5Comments

Changliu52 picture Changliu52  ·  6Comments

watakandai picture watakandai  ·  8Comments