Error switching to 'auto' mode

Hai,

I am trying to incorporate GPS aided autonomous navigation in my Autonomous Surface Vehicle (ASV) using MAVROS. When I am pushing the waypoints and then switching my FCU to ‘AUTO’ mode I am getting the following error:

I am using Pixhawk 6C with ArduRover V4.2.3.
The following is the code I am using:

#!/usr/bin/env python
import rospy
import mavros
import sensor_msgs
import yaml
from mavros_msgs.msg import *
from mavros_msgs.srv import *
from std_msgs.msg import String
from sensor_msgs.msg import NavSatFix

latitude = 0.0
longitude = 0.0
altitude = 0.0
last_waypoint = False
flight_altitude = 3   # Check altitude value before experiments

def waiter(condition):
	while True:
		if condition:
			return
		else:
			rospy.sleep(2)

def waypoint_callback(data):
	# print("\n----------waypoint_callback----------")
	global last_waypoint
	# rospy.loginfo("Got waypoint: %s", data)
	if len(data.waypoints) != 0:							# If waypoint list is not empty
		rospy.loginfo("is_current: %s", data.waypoints[len(data.waypoints)-1].is_current)
		last_waypoint = data.waypoints[len(data.waypoints)-1].is_current	# Checks status of "is_current" for last waypoint

def globalPosition_callback(data):
	# print("\n----------globalPosition_callback----------")
	global latitude
	global longitude
	global altitude
	latitude = data.latitude
	longitude = data.longitude
	altitude = data.altitude
	
def clear_pull():
	print("\n----------clear_pull----------")
	# Clearing waypoints
	rospy.wait_for_service("/mavros/mission/clear")
	waypoint_clear = rospy.ServiceProxy("/mavros/mission/clear", WaypointClear)
	resp = waypoint_clear()
	rospy.sleep(5)
	# Call waypoints_pull
	rospy.wait_for_service("/mavros/mission/pull")
	waypoint_pull = rospy.ServiceProxy("/mavros/mission/pull", WaypointPull)
	resp = waypoint_pull()
	rospy.sleep(5)
	return

def finishWaypoints():
	print("\n----------finishwaypoints----------")
	while True:						# Waits for last_waypoint in previous WaypointList to be visited
		rospy.sleep(2)
		# Waiting for last_waypoint to be true
		if last_waypoint == True:			# If last_waypoint is in the process of being visited
			while True:
				rospy.sleep(2)
				# Waiting for last_waypoint to be false
				if last_waypoint == True:	# If last_waypoint has been visited (due to previous constraint)
					break
			break
	return

def armingCall():
	print("\n----------armingCall----------")
	rospy.wait_for_service("/mavros/cmd/arming")
	asv_arm = rospy.ServiceProxy("/mavros/cmd/arming", CommandBool)
	resp = asv_arm(True)
	rospy.sleep(2)
	
def pushingWaypoints(poi):
	print("\n----------pushingWaypoints----------")
	rospy.wait_for_service("/mavros/mission/push")
	waypoint_push = rospy.ServiceProxy("/mavros/mission/push", WaypointPush)
	resp = waypoint_push(0, poi)
	rospy.sleep(5)
	return

def switch_modes(): # current_mode: int, next_mode: str (http://docs.ros.org/jade/api/mavros_msgs/html/srv/SetMode.html)
	print("\n----------switch_modes----------")
	rospy.wait_for_service("/mavros/set_mode")
	modes = rospy.ServiceProxy("/mavros/set_mode", SetMode)
	resp = modes(custom_mode ='AUTO')
	rospy.sleep(5)
	return

def disarmingCall():
	print("\n----------disarmingCall----------")
	rospy.wait_for_service("/mavros/cmd/arming")
	asv_arm = rospy.ServiceProxy("/mavros/cmd/arming", CommandBool)
	resp = asv_arm(False)
	rospy.sleep(2)

def main():
    rospy.init_node('gps_navigation_node', anonymous=True)
    rospy.Subscriber("/mavros/mission/waypoints", WaypointList, waypoint_callback)
    rospy.Subscriber("/mavros/global_position/raw/fix", NavSatFix, globalPosition_callback)
	#readyBit = rospy.Publisher("/mavros/ugv/ready", String, queue_size=10) # Flag topic
     
    clear_pull()
    
    armingCall()	

    waypoints = [
		Waypoint(frame = 3, command = 16, is_current = 0, autocontinue = True, param1 = 5, x_lat = 38.99044, y_long = -76.93776, z_alt = 0),
		Waypoint(frame = 3, command = 16, is_current = 0, autocontinue = True, param1 = 5, x_lat = 38.99066, y_long = -76.93738, z_alt = 0),
		Waypoint(frame = 3, command = 16, is_current = 0, autocontinue = True, param1 = 5, x_lat = 38.99113, y_long = -76.93747, z_alt = 0),
		Waypoint(frame = 3, command = 16, is_current = 0, autocontinue = True, param1 = 5, x_lat = 38.99079, y_long = -76.93777, z_alt = 0),
		Waypoint(frame = 3, command = 16, is_current = 0, autocontinue = True, param1 = 5, x_lat = 38.99056, y_long = -76.93791, z_alt = 0)
		]

    pushingWaypoints(waypoints)

    switch_modes() #changing from manual mode to auto mode

    finishWaypoints()

    rospy.sleep(10)

    disarmingCall()
    print("Mission completed")

    rospy.spin()


if __name__ == '__main__':
	main()

Any help would be appreciated.

Thanks.

My guess is that the waypoint commands are not being successfully uploaded to the autopilot and that is why it is failing to switch into Auto mode but I’m not sure. Maybe try loading the waypoints with MP and see if that resolves the issue.

1 Like

Thanks for the reply @rmackay9
I am able to switch the mode now with “rosrun mavros mavsys mode -c AUTO”. But after pushing the waypoints and switching to ‘AUTO’ mode the thrusters are not moving.

Also I am getting these info messages when running the ROS node:

I am using a Pixhawk 6C and the M8N GPS module. The GPS model shows green light when running this node.

Appreciate any help in identifying the problem.

Thanks

Hi @nvnanil,

I’m not much of a ROS user myself but I think maybe it would be good to try using Mission Planner as a first step to ensure the vehicle is working correctly and then after that is complete, move over to using ROS.

Sure @rmackay9 . I will try that and let you know the response.

Hai,
I am not able to calibrate my M8N compass module. Is it possible to calibrate the internal compass (Pixhawk) alone and then calibrate the external compass after that? If so how can I do it. Appreciate any help in this problem.

Thanks

Hi @nvnanil,

I guess you’re trying to do the compass calibration using the MP compass calibration screen as shown on this wiki page?

Are you seeing some sort of error when trying to calibrate the compass in the GPS module? If “yes” then the issue may be the “fitness”. You might see near the bottom of the MP screen there is a fitness drop-down so try setting it to “Relaxed” and see if that helps.

Hai @rmackay9 ,

I am following the instructions from the above mentioned page. So do you recommend calibrating both compasses (internal and external) at the same time. While calibrating it’s not showing any particular error, the calibration indication bar (green bar) for the internal compass gets completed while the green bar for the external compass still keeps on restarting after completion.

@nvnanil,

If the green bar keeps going back to the start then that means that the calibration is failing normally because there is too much interference on the compass.

It’s suspicious however that the internal is passing while the external is failing. That’s quite unusual. I wonder if perhaps you’re mixing them up?

In any case, you have two choices:

  1. disable the failing compass (it’s not a good idea to rely on the internal compass)
  2. set the COMPASS_CAL_FIT to a large number like 64 and try to calibrate it again
1 Like

Hai @rmackay9 ,

The issue was solved in the following steps:

  1. Disabled the internal compass and recalibrated the external compass (M8N GPS+Compass module)
  2. The SERVO_FUNCTION param was in RC passthru. Changed it to Throttle Left and Throttle Right

Thanks for all the support.

2 Likes