You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def set_mode(self, mode, timeout):
"""mode: PX4 mode string, timeout(int): seconds"""
rospy.loginfo("setting FCU mode: {0}".format(mode))
old_mode = self.state.mode
loop_freq = 2 # Hz
rate = rospy.Rate(loop_freq)
mode_set = False
for i in xrange(timeout * loop_freq):
if self.state.mode == mode:
mode_set = True
rospy.loginfo("set mode success | seconds: {0} of {1}".format(
i / loop_freq, timeout))
break
else:
try:
rospy.loginfo("[set_mode] : waiting for set_mode service.")
rospy.wait_for_service(service='mavros/set_mode', timeout=5.0)
rospy.loginfo("[set_mode] : set_mode service is available.")
res = self.set_mode_srv(base_mode=0, custom_mode=mode)
if not res.mode_sent:
rospy.logerr("failed to send mode command")
except rospy.ServiceException as e:
rospy.logerr(e)
except rospy.ROSException as e:
rospy.logerr("[LOGIC][set_mode][ROSException] : {}".format(e))
rate.sleep()
if(not mode_set):
rospy.logwarn("[set_mode] : failed to set mode. new mode: {0}, old mode: {1}, timeout(sec): {2}".format(mode, old_mode, timeout))
return mode_set
This is what is printed in the terminal. After this mavros freezes up, for example, nothing is published over mavros/local_position/pose topic.
[INFO] [1637270303.405313, 125.740000]: [set_mode] : setting FCU mode: OFFBOARD
[INFO] [1637270303.409133, 125.744000]: [set_mode] : waiting for set_mode service.
[INFO] [1637270303.414774, 125.748000]: [set_mode] : set_mode service is available.
[ WARN] [1637270303.435382839, 125.772000000]: CMD: Unexpected command 176, result 0
If we compare with the print statements in the function, the next line of code after the last is:
res = self.set_mode_srv(base_mode=0, custom_mode=mode)
For some reason not known to me, mavros SetMode service proxy is causing mavros to freeze up. All of the data traffic freezes, the drone doesn't switch to OFFBOARD, it doesn't ARM, it stops responding to all commands. However, the weird part is it only happens occasionally, i.e., if I restart the PX4-SITL simulation, and reattempt to set mode, the drone sometimes switches to the OFFBOARD mode, arms, and takes off successfully. Before you ask, Yes, I'm publishing setpoints to the drone at ~20 Hz. For the sake of completeness, when everything works, this is what I see in the terminal output.
[INFO] [1637338061.027372, 1194.308000]: [set_mode] : setting FCU mode: OFFBOARD
[INFO] [1637338061.029514, 1194.308000]: [set_mode] : waiting for set_mode service.
[INFO] [1637338061.036751, 1194.316000]: [set_mode] : set_mode service is available.
[ WARN] [1637338061.058234206, 1194.336000000]: CMD: Unexpected command 176, result 0
WARN [mc_pos_control] Offboard activation failed with error: Activation Failed
WARN [mc_pos_control] Position-Ctrl activation failed with error: Activation Failed
WARN [mc_pos_control] Altitude-Ctrl activation failed with error: Activation Failed
[INFO] [1637338061.627722, 1194.808000]: [set_mode] : loop: 0 seconds: 0 of 5
[INFO] [1637338061.631194, 1194.812000]: [set_mode] : waiting for set_mode service.
[INFO] [1637338061.642668, 1194.820000]: [set_mode] : set_mode service is available.
[INFO] [1637338061.836344, 1195.012000]: mode changed from MANUAL to OFFBOARD
[INFO] [1637338062.127522, 1195.308000]: [set_mode] : loop: 1 seconds: 0 of 5
[INFO] [1637338062.130300, 1195.308000]: [set_mode] : set mode success. seconds: 1 of 5
MAVROS version and platform
Mavros: HEAD detached at 1.5.2 - I have some modifications in mavros/launch/px4_config.yaml, if this is relevant, let me know and I'll upload it.
ROS: Melodic
Ubuntu: 18.04.6 LTS
Autopilot type and version
[ ] ArduPilot
[x ] PX4
Version: HEAD detached at v1.11.3
Node logs
copy output of mavros_node. Usually console where you run roslaunch
$ rosrun mavros checkid
WARNING: mavros/target_system_id not set. Used default value: 1
WARNING: mavros/target_component_id not set. Used default value: 1
NOTE: Target parameters may be unset, but that may be result of incorrect --mavros-ns option.Double check results!
ERROR. I got 0 addresses, but not your target 1:1
---
Received 0 messages, from 0 addresses
sys:comp list of messages
The text was updated successfully, but these errors were encountered:
@emileakbarzadeh No, I still experience the same problem. Every once in a while (about 30 % of the time) mavros topics stop publishing when I try to take off using the SetMode service proxy.
Issue details
I'm using the mavros/set_mode ROS service to set the mode of the drone. This is how I'm using it:
In init
In set_mode function:
This is what is printed in the terminal. After this mavros freezes up, for example, nothing is published over mavros/local_position/pose topic.
If we compare with the print statements in the function, the next line of code after the last is:
For some reason not known to me, mavros SetMode service proxy is causing mavros to freeze up. All of the data traffic freezes, the drone doesn't switch to OFFBOARD, it doesn't ARM, it stops responding to all commands. However, the weird part is it only happens occasionally, i.e., if I restart the PX4-SITL simulation, and reattempt to set mode, the drone sometimes switches to the OFFBOARD mode, arms, and takes off successfully. Before you ask, Yes, I'm publishing setpoints to the drone at ~20 Hz. For the sake of completeness, when everything works, this is what I see in the terminal output.
MAVROS version and platform
Mavros: HEAD detached at 1.5.2 - I have some modifications in mavros/launch/px4_config.yaml, if this is relevant, let me know and I'll upload it.
ROS: Melodic
Ubuntu: 18.04.6 LTS
Autopilot type and version
[ ] ArduPilot
[x ] PX4
Version: HEAD detached at v1.11.3
Node logs
Diagnostics
Check ID
The text was updated successfully, but these errors were encountered: