Offboard Mode not working with Pixhawk4 mini running latest Version of px4 firmware and mavros

#1

Hello. I am using pixhawk 4 mini with mavros and I am trying to run the exact same code given on the website


For attitude control using setpoint_attitude/attitude and off board mode. I am unable to switch to the offboard mode. There is no telem2 port on Pixhawk4 mini and I suppose that could be the issue here. I am using vicon to send the position feedback to /mavros/mocap/TF topic. I am using an onboard raspberry pi. I have an UART to usb cable and a USB to micro USB cable. I can launch the px4.launch file using the USB to microusb cable connected from raspberry pi to pixhawk. I can arm and view all the topics published by mavros and the setpoint commands I am send through a .cpp file but I get off board mode reject error. Is there any specific parameters on QGroundControl I need to configure to get this mode to work? How can I tackle this problem? Thank you in advance.

#2

@arg1885 As explained in the blog article, there are a few conditions that needs to be satisfied before you can switch into offboard mode.

So first of all,
1.what rate are you sending your attitude setpoints? You need to send setpoints continously within the time out(0.5s)
2. Are you correctly encoding time stamps into your setpoint_msgs?
3. Not having a TELEM2 is not a issue anymore, you can configure both UART ports now: https://dev.px4.io/master/en/companion_computer/pixhawk_companion.html

#3

Hello Sir. Firstly let me begin by thanking you for answering my doubt. Secondly, the tutorial you have on the website is a useful one.

Getting back to our discussion about my doubt,

  1. Yes I am sending the setpoints at 10Hz.
  2. How to check if I have time stamps encoded correctly for the setpoint messages?
  3. I am following the link you have attached for configuring the port for the companion computer. So from what I understood, let me try to summarize here (please correct me if I am wrong). The MAVlink is supposed to be configured for telem1 port of the pixhawk4 mini since I do not have telem2 port. So I will have to set the parameters as follows on the pixhawk using QGroundControl

MAV_1_CONFIG = TELEM1 (101)
Mav_1_MODE = ONBOARD (2)
MAV_1_RATE = 921600 baud.

Now, i am supposed to enter the rate in Bytes per second and 921600 is the baud rate. What is the conversion factor I should use to enter MAV_1_RATE? I will check rest of the settings and try running the example again. Thank you for your help.

#4

@Jaeyoung-Lim Hello, I followed the steps mentioned in the https://dev.px4.io/master/en/companion_computer/pixhawk_companion.html to setup my companion computer. I was able to launch px4.launch file at 921600 baud. I have configured my telem1 port to communicate with my onboard computer (companion computer). SER_TEL1_BAUD is set to 921600, MAV_1_CONFIG is set to telem1 and MAV_1_MODE to onboard. I am following the following sequence.

  1. I start the vicon and start publishing the position and quaternion data to /mavros/mocap/tf topic.
  2. Then I launch the px4.launch file.
  3. Then I arm the pixhawk using RC.
  4. I have the publishing rate of /mavros/setpoint_attitude/attitude set at 20 Hz in the code. I verified it using rostopic hz /mavros/setpoint_attitude/attitude.
  5. Then I launch the .cpp file publishing the setpoints.

I am constantly getting a warning CMD: unexpected command 176, result 0. and the pixhawk goes into the “STABILIZED” mode. Also I get a warning GP: No GPS Fix.

Do I need to use the c_uart_interface_example or MAVLink Router along with the setup I have? Are there any other settings I need to take care of in the px4_config.yaml file? Or at any other place in QGroundControl or in mavros.

Thank you for your help.

#5

@arg1885 I think you can neglect the warning for now.

a. On the companion computerside, check if your fcu_url is correctly configured
b. If you are sending a setpoint_attitude setpoint, are you sending thrust commands together?
c. You need to configure your EKF in order to make it use the mocap data you are feeding. You can look at this document

#6

Hello @Jaeyoung-Lim, I have the fcu_url set to /dev/ttyUSB0. I am sending the att_throttle messages along with the attitude setpoint messages simultaneously. Also, I have set the LPE parameters mentioned in the link you sent earlier http://dev.px4.io/en/ros/external_position_estimation.html .

When trying to switch to the Position control mode, as mentioned in the tutorial, I am not getting a position lock when I am sending the mocap/tf messages from vicon to the pixhawk (the light on the pixhawk is still blue whereas, the /mavros/state topic says it is in the position control mode. I am not sure if it is really in the position control mode since there is a position drift which could be related to the tuning of the attitude gains). Also I am still not able to get the pixhawk in the offboard mode. Is there anything else I should be tuning apart from things mentioned in setting up the LPE using vicon? I am able to see that the vicon is publishing messages to /mavros/mocap/tf and those same messages are seen when I am doing rostopic echo /mavros/mocap/tf. How to ensure that pixhawk is getting those messages?

#7

@arg1885 Do you get any logs when offboard mode is rejected? What rate are you sending the messages?

Actually, I am not sure of the current status of the LPE. It might be deprecated - it is not being maintained as far as I know. So it might be a better idea to switch to EKF2. The position drift shows that your external position estimation is not working properly

#8

@Jaeyoung-Lim I am sending the messages at 20 Hz. But my concern is if it is not getting the position lock I doubt if the position control would work too. Should I switch off the GPS? Also I am not seeing any changes in the local position. It is almost 0 in all the directions.

#9

@arg1885 I would suggest to switch your estimator to EKF2, and configure the external vision input to make the estimator use the vicon data. If you have GPS connected, you need to switch it off

#10

@Jaeyoung-Lim Is there a specific parameter to enable external vision input to make EKF use the Vicon data? I have used EKF2_AID_MASK to use vision position and yaw. Now my question is if I am using vision, should I still be publishing the Vicon data to /mavros/mocap/tf or vision?

#11

@arg1885 You should publish to vision.

#12

@Jaeyoung-Lim Ok. I will try that. Thank you for your help. I got the position control to work with GPS lock.

#13

Hello All,

I have been facing similar issue where I have all the above said procedure setup in-place. About my hardware I’m using an rpi-3 as my companion pc and the same is connected to Pixhawk mini 4 via USB port of pi to the micro-usb debug port of Pixhawk. Im able to arm the Pixhawk via stabilized mode. later I feed the motion capture data to Pixhawk via encoding SET_POSITION_LOCAL_TARGET_NED at 120 HZ. As suggest from few sites I tried checking the MAVLink inspector to find if the same coordinates I fed is reflected on Pixhawk MAVLink stream. But I noticed it was not getting reflected as sent from companion pc.

And when I set the rc switch to off board mode to handle off board operation it doesn’t take off to an desired height(altitude) that we set while encoding.

Not sure as what’s is happening here. I appreciate all you’re help on this.

Note: Im using the drone-kit version of MAVLink interface.

Thanks,
scalnoor

#14

@scalnoor, does your /mavros/local_pose/pose match the mocap or vicon data?

#15

@Jaeyoung-Lim I was able to put my pixhawk in offboard mode using vicon. everything seems to work fine now. Thank you for all your help. I have a new question now. If I set the position of my quadcopter using setpoint messages and I want to switch it to the attitude control how can I determine the thrust value which I need to provide along the the setpoint attitude messages in order to avoid crash?

#16

@arg1885, Hello good to hear that its working fine for you. I wanted ask you were you able to get mocap data to pixhawk and were you able see the same on mavlink inspector LOCAL_POSITION in NED ?

In my case i am not able to get mocap data into pixhawk, can you please explain how your setup is configured to pixhawk and the configuration that you followed?

Thanks,
Sagar

#17

@arg1885 can you please explain how you successfully put the controller to offboard ?

#18

@arg1885 The thrust you can command is a normalized thrust value which maps to 1 as maximum thrust, 0 as minimum. Since there is no information of your hardware available in the software, you need to map the thrust values for your system.

@scalnoor Have you checked if you configured the EKF2_AID_MASK configured properly?

#19

Hello @Jaeyoung-Lim, thank you responding , I really appreciate you help . Yes I have followed complete instructions from https://dev.px4.io/en/ros/external_position_estimation.html# . And yes I am setting EKF2_AID_MASK to 24 bit mask to use vision fusion and yaw. I have been sending mocap data through MAVlink API library and NOT ROS. I’m using ATT_POS_MOCAP message to encode the position in NED format. But still it doesn’t reflect the value in MAVlink inspector. I also extracted the Ulog and checked the parsed file for at_pos_mocap.csv but could not find one and the ekf2_innovation.csv files are reading mocap data.

#20

Hello @scalnoor this is coming from the discussion here

  • relay mocap pose topic to /mavros/vision_pose/pose
  • Adjust EKF_AID_MASK to fuse vision position and yaw
  • adjust height parameter EKF2_HGT_MODE` to use vision
  • reduce EKF2_EVDELAY if you are getting mocap pose at high rate. I reduced it to 50ms . I don’t know how to get accurate estimate of that parameter, though.
  • reboot FCU for the parameters to take effect
  • Make sure that /mavros/local_pose/pose are very close to the mocap pose topic

I followed these steps and I was able to put the pixhawk in offboard mode and position control mode.