Skip to content

Commit

Permalink
Had while statement in the wrong place
Browse files Browse the repository at this point in the history
Got threaded polling working correctly
  • Loading branch information
zlite committed Aug 6, 2023
1 parent 19d898c commit eb983d9
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions donkeycar/parts/mavlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,32 @@ def __init__(self, connection_string):


def update(self):
self.poll()
while self.running:
self.poll()

def poll(self):
if self.running:
message = self.master.recv_match()
if message is not None:
attitude_msg = self.master.recv_match(type='ATTITUDE', blocking=True)
position_msg = self.master.recv_match(type='GLOBAL_POSITION_INT', blocking=True)
velocity_msg = self.master.recv_match(type='VFR_HUD', blocking=True)
message = self.master.recv_match()
if message is not None:
attitude_msg = self.master.recv_match(type='ATTITUDE', blocking=True)
position_msg = self.master.recv_match(type='GLOBAL_POSITION_INT', blocking=True)
velocity_msg = self.master.recv_match(type='VFR_HUD', blocking=True)

# Updating IMU data
self.roll = attitude_msg.roll
self.pitch = attitude_msg.pitch
self.yaw = attitude_msg.yaw
# Updating IMU data
self.roll = attitude_msg.roll
self.pitch = attitude_msg.pitch
self.yaw = attitude_msg.yaw

# Updating Position data
self.lat = position_msg.lat / 1e7 # Convert to degrees
self.lon = position_msg.lon / 1e7 # Convert to degrees
self.alt = position_msg.alt / 1e3 # Convert to meters
# Updating Position data
self.lat = position_msg.lat / 1e7 # Convert to degrees
self.lon = position_msg.lon / 1e7 # Convert to degrees
self.alt = position_msg.alt / 1e3 # Convert to meters

# Updating Velocity data (VFR_HUD provides ground speeds)
self.vx = velocity_msg.groundspeed * math.cos(self.yaw)
self.vy = velocity_msg.groundspeed * math.sin(self.yaw)
self.vz = velocity_msg.climb
# Updating Velocity data (VFR_HUD provides ground speeds)
self.vx = velocity_msg.groundspeed * math.cos(self.yaw)
self.vy = velocity_msg.groundspeed * math.sin(self.yaw)
self.vz = velocity_msg.climb
else:
print("no Mavlink data")

def run_threaded(self):
return (self.roll, self.pitch, self.yaw,
Expand Down

0 comments on commit eb983d9

Please sign in to comment.