Mavros: Is there a topic like /mavros/setpoint_velocity/cmd_vel but use body frame?

Created on 25 Aug 2017  ·  14Comments  ·  Source: mavlink/mavros

Hi,
I am doing vision-based control and the camera is on the drone facing down.
So the position estimation is in body frame.
I found the topic /mavros/setpoint_velocity/cmd_vel can be used to change the drone's speed but it seems it is in NED frame.

Is there a topic like /mavros/setpoint_velocity/cmd_vel but use body frame?

Or I need to convert my speed setpoint from body frame to NED frame to implement it?

I tried to find something that I can use and I found this code. https://github.com/weiweikong/px4_velocity_control_keyboard/blob/master/src/px4_velocity_control_node.cpp

vs_body_axis.twist.linear.x = vs.twist.linear.x * cos(uavYawENU) + vs.twist.linear.y * sin(uavYawENU);
vs_body_axis.twist.linear.y = vs.twist.linear.x * sin(uavYawENU) - vs.twist.linear.y * cos(uavYawENU);

It seems this is the best solution I could find.
I am not sure if the Yaw is from IMU only or from fusion of IMU and magnetic.
Do you have some comments or ideas about this?

MAVROS version and platform

Mavros: 0.17.3
ROS: Indigo
Ubuntu: 14.04

Autopilot type and version

APM:Copter V3.4-dev (fe724032)

Node logs

bshang2@mechatronics-990:~/simulation/ardupilot/ArduCopter$ roslaunch ardupilot_sitl_gazebo_plugin erlecopter_mark.launch
... logging to /home/bshang2/.ros/log/ca9213bc-89bf-11e7-b657-1803733b65bb/roslaunch-mechatronics-990-28079.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://mechatronics-990:45006/

SUMMARY

CLEAR PARAMETERS

  • /mavros/

PARAMETERS

  • /mavros/cmd/use_comp_id_system_control: False
  • /mavros/conn/heartbeat_rate: 1.0
  • /mavros/conn/system_time_rate: 0.0
  • /mavros/conn/timeout: 10.0
  • /mavros/conn/timesync_rate: 0.0
  • /mavros/fcu_url: tcp://127.0.0.1:5760
  • /mavros/gcs_url: udp://127.0.0.1@1...
  • /mavros/global_position/frame_id: fcu
  • /mavros/global_position/rot_covariance: 99999.0
  • /mavros/global_position/tf/child_frame_id: fcu_utm
  • /mavros/global_position/tf/frame_id: local_origin
  • /mavros/global_position/tf/send: False
  • /mavros/image/frame_id: px4flow
  • /mavros/imu/angular_velocity_stdev: 0.000349065850399
  • /mavros/imu/frame_id: fcu
  • /mavros/imu/linear_acceleration_stdev: 0.0003
  • /mavros/imu/magnetic_stdev: 0.0
  • /mavros/imu/orientation_stdev: 1.0
  • /mavros/local_position/frame_id: fcu
  • /mavros/local_position/tf/child_frame_id: base_link
  • /mavros/local_position/tf/frame_id: world
  • /mavros/local_position/tf/send: True
  • /mavros/mission/pull_after_gcs: True
  • /mavros/mocap/use_pose: True
  • /mavros/mocap/use_tf: False
  • /mavros/plugin_blacklist: ['actuator_contro...
  • /mavros/plugin_whitelist: []
  • /mavros/px4flow/frame_id: px4flow
  • /mavros/px4flow/ranger_fov: 0.0
  • /mavros/px4flow/ranger_max_range: 5.0
  • /mavros/px4flow/ranger_min_range: 0.3
  • /mavros/safety_area/p1/x: 1.0
  • /mavros/safety_area/p1/y: 1.0
  • /mavros/safety_area/p1/z: 1.0
  • /mavros/safety_area/p2/x: -1.0
  • /mavros/safety_area/p2/y: -1.0
  • /mavros/safety_area/p2/z: -1.0
  • /mavros/setpoint_accel/send_force: False
  • /mavros/setpoint_attitude/reverse_throttle: False
  • /mavros/setpoint_attitude/tf/child_frame_id: attitude
  • /mavros/setpoint_attitude/tf/frame_id: local_origin
  • /mavros/setpoint_attitude/tf/listen: False
  • /mavros/setpoint_attitude/tf/rate_limit: 10.0
  • /mavros/setpoint_position/tf/child_frame_id: setpoint
  • /mavros/setpoint_position/tf/frame_id: local_origin
  • /mavros/setpoint_position/tf/listen: False
  • /mavros/setpoint_position/tf/rate_limit: 50.0
  • /mavros/startup_px4_usb_quirk: False
  • /mavros/sys/disable_diag: False
  • /mavros/sys/min_voltage: 10.0
  • /mavros/target_component_id: 1
  • /mavros/target_system_id: 1
  • /mavros/tdr_radio/low_rssi: 40
  • /mavros/time/time_ref_source: fcu
  • /mavros/time/timesync_avg_alpha: 0.6
  • /mavros/vibration/frame_id: vibration
  • /mavros/vision_pose/tf/child_frame_id: vision
  • /mavros/vision_pose/tf/frame_id: local_origin
  • /mavros/vision_pose/tf/listen: False
  • /mavros/vision_pose/tf/rate_limit: 10.0
  • /mavros/vision_speed/listen_twist: False
  • /robot_description:
  • /rosdistro: indigo
  • /rosversion: 1.11.21
  • /tf_prefix:
  • /use_sim_time: True

NODES
/
gazebo (gazebo_ros/gzserver)
gazebo_gui (gazebo_ros/gzclient)
mavros (mavros/mavros_node)
spawn_erlecopter (gazebo_ros/spawn_model)

auto-starting new master
process[master]: started with pid [28094]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to ca9213bc-89bf-11e7-b657-1803733b65bb
process[rosout-1]: started with pid [28107]
started core service [/rosout]
process[mavros-2]: started with pid [28126]
process[spawn_erlecopter-3]: started with pid [28133]
process[gazebo-4]: started with pid [28134]
process[gazebo_gui-5]: started with pid [28151]
spawn_model script started
[gazebo-4] process has died [pid 28134, exit code 255, cmd /home/bshang2/simulation/ros_catkin_ws/src/gazebo_ros_pkgs/gazebo_ros/scripts/gzserver -u -e ode /home/bshang2/simulation/ros_catkin_ws/src/ardupilot_sitl_gazebo_plugin/ardupilot_sitl_gazebo_plugin/worlds/mark_world/mark.world __name:=gazebo __log:=/home/bshang2/.ros/log/ca9213bc-89bf-11e7-b657-1803733b65bb/gazebo-4.log].
log file: /home/bshang2/.ros/log/ca9213bc-89bf-11e7-b657-1803733b65bb/gazebo-4.log
[INFO] [WallTime: 1503684250.172508] [0.000000] Loading model xml from ros parameter
[INFO] [WallTime: 1503684250.176886] [0.000000] Waiting for service /gazebo/spawn_urdf_model
[gazebo_gui-5] process has died [pid 28151, exit code 255, cmd /home/bshang2/simulation/ros_catkin_ws/src/gazebo_ros_pkgs/gazebo_ros/scripts/gzclient __name:=gazebo_gui __log:=/home/bshang2/.ros/log/ca9213bc-89bf-11e7-b657-1803733b65bb/gazebo_gui-5.log].
log file: /home/bshang2/.ros/log/ca9213bc-89bf-11e7-b657-1803733b65bb/gazebo_gui-5
.log
^C[spawn_erlecopter-3] killing on exit
[mavros-2] killing on exit
Traceback (most recent call last):
File "/home/bshang2/simulation/ros_catkin_ws/src/gazebo_ros_pkgs/gazebo_ros/scripts/spawn_model", line 301, in
sm.callSpawnService()
File "/home/bshang2/simulation/ros_catkin_ws/src/gazebo_ros_pkgs/gazebo_ros/scripts/spawn_model", line 267, in callSpawnService
initial_pose, self.reference_frame, self.gazebo_namespace)
File "/home/bshang2/simulation/ros_catkin_ws/src/gazebo_ros_pkgs/gazebo_ros/src/gazebo_ros/gazebo_interface.py", line 28, in spawn_urdf_model_client
rospy.wait_for_service(gazebo_namespace+'/spawn_urdf_model')
File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py", line 159, in wait_for_service
raise ROSInterruptException("rospy shutdown")
rospy.exceptions.ROSInterruptException: rospy shutdown
^C[rosout-1] killing on exit
^C[master] killing on exit
shutting down processing monitor...
... shutting down processing monitor complete
done
bshang2@mechatronics-990:~/simulation/ardupilot/ArduCopter$ roslaunch ardupilot_sitl_gazebo_plugin erlecopter_mark.launch
... logging to /home/bshang2/.ros/log/e483c856-89bf-11e7-bb61-1803733b65bb/roslaunch-mechatronics-990-28603.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://mechatronics-990:41224/

SUMMARY

CLEAR PARAMETERS

  • /mavros/

PARAMETERS

  • /mavros/cmd/use_comp_id_system_control: False
  • /mavros/conn/heartbeat_rate: 1.0
  • /mavros/conn/system_time_rate: 0.0
  • /mavros/conn/timeout: 10.0
  • /mavros/conn/timesync_rate: 0.0
  • /mavros/fcu_url: tcp://127.0.0.1:5760
  • /mavros/gcs_url: udp://127.0.0.1@1...
  • /mavros/global_position/frame_id: fcu
  • /mavros/global_position/rot_covariance: 99999.0
  • /mavros/global_position/tf/child_frame_id: fcu_utm
  • /mavros/global_position/tf/frame_id: local_origin
  • /mavros/global_position/tf/send: False
  • /mavros/image/frame_id: px4flow
  • /mavros/imu/angular_velocity_stdev: 0.000349065850399
  • /mavros/imu/frame_id: fcu
  • /mavros/imu/linear_acceleration_stdev: 0.0003
  • /mavros/imu/magnetic_stdev: 0.0
  • /mavros/imu/orientation_stdev: 1.0
  • /mavros/local_position/frame_id: fcu
  • /mavros/local_position/tf/child_frame_id: base_link
  • /mavros/local_position/tf/frame_id: world
  • /mavros/local_position/tf/send: True
  • /mavros/mission/pull_after_gcs: True
  • /mavros/mocap/use_pose: True
  • /mavros/mocap/use_tf: False
  • /mavros/plugin_blacklist: ['actuator_contro...
  • /mavros/plugin_whitelist: []
  • /mavros/px4flow/frame_id: px4flow
  • /mavros/px4flow/ranger_fov: 0.0
  • /mavros/px4flow/ranger_max_range: 5.0
  • /mavros/px4flow/ranger_min_range: 0.3
  • /mavros/safety_area/p1/x: 1.0
  • /mavros/safety_area/p1/y: 1.0
  • /mavros/safety_area/p1/z: 1.0
  • /mavros/safety_area/p2/x: -1.0
  • /mavros/safety_area/p2/y: -1.0
  • /mavros/safety_area/p2/z: -1.0
  • /mavros/setpoint_accel/send_force: False
  • /mavros/setpoint_attitude/reverse_throttle: False
  • /mavros/setpoint_attitude/tf/child_frame_id: attitude
  • /mavros/setpoint_attitude/tf/frame_id: local_origin
  • /mavros/setpoint_attitude/tf/listen: False
  • /mavros/setpoint_attitude/tf/rate_limit: 10.0
  • /mavros/setpoint_position/tf/child_frame_id: setpoint
  • /mavros/setpoint_position/tf/frame_id: local_origin
  • /mavros/setpoint_position/tf/listen: False
  • /mavros/setpoint_position/tf/rate_limit: 50.0
  • /mavros/startup_px4_usb_quirk: False
  • /mavros/sys/disable_diag: False
  • /mavros/sys/min_voltage: 10.0
  • /mavros/target_component_id: 1
  • /mavros/target_system_id: 1
  • /mavros/tdr_radio/low_rssi: 40
  • /mavros/time/time_ref_source: fcu
  • /mavros/time/timesync_avg_alpha: 0.6
  • /mavros/vibration/frame_id: vibration
  • /mavros/vision_pose/tf/child_frame_id: vision
  • /mavros/vision_pose/tf/frame_id: local_origin
  • /mavros/vision_pose/tf/listen: False
  • /mavros/vision_pose/tf/rate_limit: 10.0
  • /mavros/vision_speed/listen_twist: False
  • /robot_description:
  • /rosdistro: indigo
  • /rosversion: 1.11.21
  • /tf_prefix:
  • /use_sim_time: True

NODES
/
gazebo (gazebo_ros/gzserver)
gazebo_gui (gazebo_ros/gzclient)
mavros (mavros/mavros_node)
spawn_erlecopter (gazebo_ros/spawn_model)

auto-starting new master
process[master]: started with pid [28618]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to e483c856-89bf-11e7-bb61-1803733b65bb
process[rosout-1]: started with pid [28631]
started core service [/rosout]
process[mavros-2]: started with pid [28656]
process[spawn_erlecopter-3]: started with pid [28657]
process[gazebo-4]: started with pid [28674]
process[gazebo_gui-5]: started with pid [28678]
spawn_model script started
[INFO] [WallTime: 1503684293.653120] [0.000000] Loading model xml from ros parameter
[INFO] [WallTime: 1503684293.657344] [0.000000] Waiting for service /gazebo/spawn_urdf_model
[INFO] [WallTime: 1503684294.260952] [0.047500] Calling service /gazebo/spawn_urdf_model
[INFO] [WallTime: 1503684294.855628] [0.445000] Spawn status: SpawnModel: Successfully spawned model
[spawn_erlecopter-3] process has finished cleanly
log file: /home/bshang2/.ros/log/e483c856-89bf-11e7-bb61-1803733b65bb/spawn_erlecopter-3*.log

Diagnostics

bshang2@mechatronics-990:~/simulation/ardupilot/ArduCopter$ rostopic echo -n1 /diagnostics
header:
seq: 6456
stamp:
secs: 6817
nsecs: 500000000
frame_id: ''
status:


  • level: 0
    name: mavros: FCU connection
    message: connected
    hardware_id: tcp://127.0.0.1:5760
    values:



    • key: Received packets:

      value: 24635



    • key: Dropped packets:

      value: 0



    • key: Buffer overruns:

      value: 0



    • key: Parse errors:

      value: 0



    • key: Rx sequence number:

      value: 58



    • key: Tx sequence number:

      value: 190



    • key: Rx total bytes:

      value: 19770100



    • key: Tx total bytes:

      value: 169295



    • key: Rx speed:

      value: inf



    • key: Tx speed:

      value: inf


  • level: 0
    name: mavros: GCS bridge
    message: connected
    hardware_id: tcp://127.0.0.1:5760
    values:



    • key: Received packets:

      value: 3059



    • key: Dropped packets:

      value: 0



    • key: Buffer overruns:

      value: 0



    • key: Parse errors:

      value: 0



    • key: Rx sequence number:

      value: 243



    • key: Tx sequence number:

      value: 0



    • key: Rx total bytes:

      value: 51809



    • key: Tx total bytes:

      value: 19769923



    • key: Rx speed:

      value: inf



    • key: Tx speed:

      value: inf


  • level: 0
    name: mavros: GPS
    message: 3D fix
    hardware_id: tcp://127.0.0.1:5760
    values:



    • key: Satellites visible

      value: 10



    • key: Fix type

      value: 3



    • key: EPH (m)

      value: 1.21



    • key: EPV (m)

      value: 2.00


  • level: 0
    name: mavros: Heartbeat
    message: Normal
    hardware_id: tcp://127.0.0.1:5760
    values:



    • key: Heartbeats since startup

      value: 6817



    • key: Frequency (Hz)

      value: 0.952381



    • key: Vehicle type

      value: Quadrotor



    • key: Autopilot type

      value: ArduPilotMega



    • key: Mode

      value: GUIDED



    • key: System status

      value: Active


  • level: 0
    name: mavros: System
    message: Normal
    hardware_id: tcp://127.0.0.1:5760
    values:



    • key: Sensor present

      value: 0x0061FD2F



    • key: Sensor enabled

      value: 0x0061FD2F



    • key: Sensor helth

      value: 0x0061FD2F



    • key: Sensor 3D Gyro

      value: Ok



    • key: Sensor 3D Accel

      value: Ok



    • key: Sensor 3D Mag

      value: Ok



    • key: Sensor Abs Pressure

      value: Ok



    • key: Sensor GPS

      value: Ok



    • key: Sensor Laser Position

      value: Ok



    • key: Sensor Ang Rate Control

      value: Ok



    • key: Sensor Attitude Stab

      value: Ok



    • key: Sensor Yaw Position

      value: Ok



    • key: Sensor Z/Alt Control

      value: Ok



    • key: Sensor X/Y Pos Control

      value: Ok



    • key: Sensor Motor Outputs

      value: Ok



    • key: Sensor RC Receiver

      value: Ok



    • key: AHRS health

      value: Ok



    • key: Terrain health

      value: Ok



    • key: CPU Load (%)

      value: 0.0



    • key: Drop rate (%)

      value: 0.0



    • key: Errors comm

      value: 0



    • key: Errors count #1

      value: 0



    • key: Errors count #2

      value: 0



    • key: Errors count #3

      value: 0



    • key: Errors count #4

      value: 0


  • level: 1
    name: mavros: Battery
    message: Low voltage
    hardware_id: tcp://127.0.0.1:5760
    values:



    • key: Voltage

      value: 0.00



    • key: Current

      value: 0.0



    • key: Remaining

value: 100.0

Check ID

bshang2@mechatronics-990:~/simulation/ardupilot/ArduCopter$ rosrun mavros checkid
OK. I got messages from 1:1.


Received 1231 messages, from 1 addresses
sys:comp list of messages
1:1 0, 1, 2, 136, 152, 150, 24, 27, 29, 30, 32, 33, 162, 163, 164, 165, 42, 173, 178, 62, 193, 74, 35, 36, 241, 116

question

Most helpful comment

For setpoint_velocity, I will add a fix which will allows choosing between the LOCAL_NED and the BODY_NED, since it currently is defaulted to LOCAL_NED (https://github.com/mavlink/mavros/blob/master/mavros/src/plugins/setpoint_velocity.cpp#L81). In the mean time, you can use setpoint_raw and set the coordinate_frame to FRAME_BODY_NED or MAV_FRAME::BODY_NED (both should work).

All 14 comments

Hey there,

You can use the setpoint_raw.

http://wiki.ros.org/mavros#mavros.2BAC8-Plugins.setpoint_raw

On the target setpoint, you can change the coordinate frame.

http://docs.ros.org/api/mavros_msgs/html/msg/PositionTarget.html

For setpoint_velocity, I will add a fix which will allows choosing between the LOCAL_NED and the BODY_NED, since it currently is defaulted to LOCAL_NED (https://github.com/mavlink/mavros/blob/master/mavros/src/plugins/setpoint_velocity.cpp#L81). In the mean time, you can use setpoint_raw and set the coordinate_frame to FRAME_BODY_NED or MAV_FRAME::BODY_NED (both should work).

Thanks @AlexisTM and @TSC21 Your reply is helpful. I will try that later.

@TSC21 @AlexisTM Thanks for your help! I can control the velocity in body frame now. Video is recorded: https://www.youtube.com/watch?v=dyUQfFYX3pk&feature=youtu.be

rostopic pub /mavros/setpoint_raw/local mavros_msgs/PositionTarget '{header: {stamp: now, frame_id: "world"}, coordinate_frame: 8, type_mask: 3527, velocity: {x: 0.1, y: 0, z: 0}}' -r 10

@cnpcshangbo good to know

hi @cnpcshangbo, thank you for the video.
I post this to help others clearing a confusion that I had.
Even though the frame mask is FRAME_BODY_NED = 8 , the ROS command should still be in ENU . The ENU -> NED conversion is taken care by mavros.
In fact, from the video, the behavior is:

  • x = 0.1 ---> To the right
  • y = 0.1 ---> Forward
    Obviously it is still in ENU. However, this confusion cost me a week of pulling hair...

Hi Hoang,
Thank you for your clarification.
Sorry to hear that it took you so long time.
Your efforts help other.
Thanks
Bo

Hoang Minh Chung notifications@github.com于2018年8月17日 周五上午11:09写道:

hi @cnpcshangbo https://github.com/cnpcshangbo, thank you for the video.
I post this to help others clearing a confusion that I had.
Even though the frame mask is "FRAME_BODY_NED = 8", the ROS command
should still be in ENU
. The ENU -> NED conversion will be done by
mavros.
In fact, from the video, the behavior is:

  • x = 0.1 ---> To the right
  • y = 0.1 ---> Forward
    Obviously it is still in ENU. However, this confusion cost me a week
    of pulling hair...


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/mavlink/mavros/issues/792#issuecomment-413745084, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AEm3NdefOViosyJKxQlf2h0ZweC8lO6uks5uRjP9gaJpZM4PDCb2
.

Isn't it supposed to be x forward and y to the left for BODY and x to East, y to North in the map frame @Nuno?

So am I correct that we actually have 3 conventions here:
1) NED: PX4 onboard estimation and control
2) ENU: standard input format for mavros command messages
3) NWU: Typical coordinate system in ROS

No. There's no NWU in ROS.
http://www.ros.org/reps/rep-0103.html

@AlexisTM north or east should no be used to specify body conventions, but rather orientations like front, left.

Okay. But if I am not wrong, I think we still have 3 conventions?
1) NED: Onboard control
2) Right-Forward-Up: How mavros understands raw (velocity) setpoints
3) Forward-Left-Up: ROS convention

@hmchung We are using velocity setpoints within the map frame and it is ENU (ROS convention)

Note that there should be only 2 conventions! NED on the Pixhawk and ENU: anything you do on ROS.

Forward-Left-Up (FLU) is the ROS convention for the body frame. East-North-Up (ENU) is the ROS convention for the local/word frame.

Was this page helpful?
0 / 5 - 0 ratings