Hello. Our team stumbled upon strange problem:
We are using the lidar PSK-CM8JL65-CC5 to read the attitude of our drone (pixhawk 4). Reading the value from rangefinder2 in mission planner is no problem - with delay about 0.5 sec it gets to the mission planner. But reading it from RPi Zero as companion computer…
We are using the pymavlink, our code is basically:
usemavlink = 1
if usemavlink:
connection_string = ‘/dev/serial0, 57600’
master = mavutil.mavlink_connection(connection_string)
print(“Waiting for heartbeat”)
master.wait_heartbeat()
print(“Heartbeat from system (system %u component %u)” % (master.target_system, master.target_component))
message = master.mav.command_long_encode(
master.target_system, # Target system ID
master.target_component, # Target component ID
mavutil.mavlink.MAV_CMD_SET_MESSAGE_INTERVAL, # ID of command to send
0, # Confirmation
132, # param1: Message ID to be streamed
1000000, # param2: Interval in microseconds
0, # param3 (unused)
0, # param4 (unused)
0, # param5 (unused)
0, # param5 (unused)
0 # param6 (unused)
)
def nothing(n):
pass
def getdistance():
if usemavlink:
print(“Request sent - waiting for response”)
# Wait for a response (blocking) to the MAV_CMD_SET_MESSAGE_INTERVAL command and print result
response = master.recv_match(blocking=True)
print(response)
if response is not None and response.get_type() == ‘DISTANCE_SENSOR’:
print(“Command accepted”)
return response.current_distance
else:
print(“Command failed”)
return 000
else:
return 000
while True:
master.mav.send(message)
print(getdistance())
time.sleep(1)
The ID of sensor (is 1, as i should be for rangefinder2), the timeboot values (the difference from response to response is up to real time) are correct, ALWAYS, but the longer we run the code - the bigger the delay between updating the “current_distance” value and the value of rangefinder2 of mission planner. The distance_sensor message is being sent by mavlink just fine, without any delay, every 1 second, it is only the current_distance value that is being delayed more and more… The “Accumulative delay” I name it.
I’d be very happy with any help on it, at this point I ran out of ideas to solve it. We tried:
- Changing the interval in mav.command_long_encode
- Setting different (256000) baudrate
- Listening to any response with recv_match(blocking=False), without blocking
No go, nothing of those resolved our case