Fixed movements with Pixhawk

Hi there, is it possible to program fixed rotations using pymavlink? For example, I would like the sub to do a 360 rotation to the right, returning to its original heading, and then stop. I have tried polling the heading data, however, it does not poll fast enough and often overshoots where it was supposed to stop. Is there a better approach to this?

Hi Alex,

Can you share your code ?
If the ROV is overshooting while using pymavlink, make sure that your yaw PID is tuned.
Take a look in the *_YAW_P, *_YAW_I, *_YAW_D parameters.

Sure, here is some of the code we were using.

This was the main method called to perform the rotations. This code was sloppy as it was a test.

if getHeading(connection) is not None:
startHeading = getHeading(connection)
counter = 0

while(counter < 2):
  #rotateLeft_Mob(connection)
  if getHeading(connection) > startHeading - 5 and getHeading(connection) < startHeading - 1:
    counter += 1

return “END_STATE”

This code was meant to make the robot perform 2 360s with some degree of error, as we could not find a surefire way to do a perfect 360.

These are the methods mentioned in the above piece of code:

def leftward_Mob(connection):
connection.mav.manual_control_send(
connection.target_system,
0,
-1*curr_throttle,
500,
0,
0)

This method rotated the robot to the left.

def getHeading(connection):
msg = connection.recv_match(blocking=True)
msgTypes = set()

msgTypes.add(msg.get_type())
if msg.get_type() == ‘AHRS2’:
yaw = msg.to_dict()[‘yaw’]
yawDegrees = round(yaw * 360 / (2 * 3.14), 1)
return(“%f” % (yawDegrees))

This method pulled the “yaw” value using pymavlink.

Do you have any ideas on how to better implement this? This was an admittedly messy implementation that worked with a large degree of error only some of the time.