# Changing MPC_XY_VEL_MAX in flight, in offboard, with python script

Hello,

I am trying to figure out how to change the MPC_XY_VEL_MAX parameter in the px4 parameters via this code:

At the top I have:

    from mavros_msgs.srv import *


Then in a function under a class called fcuModes I have:

    def setVelocity(self, velocity):
rospy.wait_for_service('param/set')
try:
velocitySetService = rospy.ServiceProxy('param/set', mavros_msgs.srv.ParamSet)
velocitySetService(velocity)
rospy.logwarn('Just tried to set velocity parameter')
except rospy.ServiceException, e:
rospy.logwarn('FAILED to set velocity parameter')
print "service ParamSet call failed: %s. Velocity could not be set."%e


I have another class called Controller where I define:

   self.maxvelocity = ParamSet()
self.modes = fcuModes()


Finally, in my main() I set K = Controller() and then later write:

  K.maxvelocity.param_id = 'MPC_XY_VEL_MAX'
K.maxvelocity.value = 2
rospy.logwarn('Am about to try to set velocity')
K.modes.setVelocity(K.maxvelocity)
rospy.logwarn('Just tried to set velocity parameter')


I run it in simulation, but every time I do, it kicks out of OFFBOARD mode. It doesn't actually throw any errors though, but it gets stuck at the line velocitySetService = rospy.ServiceProxy('param/set', mavros_msgs.srv.ParamSet)

I have tried differeint things for mavvelocity like mavvelocity.real, mavvelocity.integer, etc but I still get the same results.

Can anyone tell me why it goes out of Offboard mode?

Thanks,

edit retag close merge delete