Currently i’m using the ROV playground by patrick electric to interact with my physical BlueROV2.
I’m having trouble arming the vehicle through code.
In the playground this is done using the user_mav.launch file which calls the user.py script. This contains the following function. arm function source
def arm(self):
""" Arm the vehicle and trigger the disarm
"""
rospy.wait_for_service('/mavros/cmd/arming')
self.arm_service = rospy.ServiceProxy('/mavros/cmd/arming', CommandBool)
self.arm_service(True)
# Disarm is necessary when shutting down
rospy.on_shutdown(self.disarm)
I can print out the respons and receive a correct message: success: True
result: 0
Looking at topic /mavros/state/ => armed=False at this point and indeed rov doesn’t respond to controller inputs.
If i call the service “/mavros/cmd/arming” from rqt, set arming to True I receive the same respons message => the topic “mavros/state” gets set to True => ROV now responds to inputs controller.
Is there a difference between how rospy calls the service and rqt? Ideally I would like to arm the bluerov from the code.
Update:
I’m currently able to arm the BlueROV from code by calling the service mavros/cmd/arming multiple times in a row. I’m not sure this is a robust solution.
rosservice call /mavros/cmd/arming True this works from the 1st time.
Right now I use the following function on start-up. I call the arming service 4 times. This has worked each time for now. If i call the service only once through code it never works. I also tried your code above, but it doesn’t work first time either.
def arm(self):
""" Arm the vehicle and trigger the disarm
"""
print("Waiting for arm service")
rospy.wait_for_service('/mavros/cmd/arming')
self.arm_service = rospy.ServiceProxy('/mavros/cmd/arming', CommandBool)
print("Arming ROV")
for _ in range(4):
print("response: ", self.arm_service(True))
time.sleep(0.5)
# Disarm is necessary when shutting down
rospy.on_shutdown(self.disarm)