Closed
Description
Currently I'm working with a Raspberry Pi 4B and a Pixhawk 4, the Pi and Pixhawk are communicating over a serial connection which connects a USB port on the Pi to the telem2 port on the Pixhawk.
Here are some relevant settings:
SER_TEL1_BAUD = 57600 8N1
SER_TEL2_BAUD = 921600 8N1
MAV_0_CONFIG = TELEM1
MAV_1_CONFIG = TELEM1
MAV_2_CONFIG = TELEM2
The serial connection works, however whenever I first run the solution on the Raspi via python3 main.py
it results in the following error.
__anext__ grpc exception
Traceback (most recent call last):
File "/home/pi/connection-test/venv/lib/python3.9/site-packages/aiogrpc/utils.py", line 145, in cb
fut.result()
File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/pi/connection-test/venv/lib/python3.9/site-packages/aiogrpc/utils.py", line 131, in _next
return next(self._iterator)
File "/home/pi/connection-test/venv/lib/python3.9/site-packages/grpc/_channel.py", line 426, in __next__
return self._next()
File "/home/pi/connection-test/venv/lib/python3.9/site-packages/grpc/_channel.py", line 826, in _next
raise self
grpc._channel._MultiThreadedRendezvous: <_MultiThreadedRendezvous of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "Connection reset by peer"
debug_error_string = "{"created":"@1648686218.868823056","description":"Error received from peer ipv6:[::1]:50051","file":"src/core/lib/surface/call.cc","file_line":903,"grpc_message":"Connection reset by peer","grpc_status":14}"
If I then stop the solution ctrl+c
then run it again python3 main.py
it works flawlessly. Every subsequent run the solution works as expected it is only the initial run that causes this error.
If I then turn off the Raspi and take the same course of action the same pattern follows.
main.py
import asyncio
from mavsdk import System
system = System()
async def check_connection_state():
print("Attempting to connect to flight controller")
async for connection_state in system.core.connection_state():
if connection_state.is_connected:
print("Success, connected to flight controller")
else:
print("Disconnected from flight controller")
async def get_armed_status():
async for armed in system.telemetry.armed():
print(armed)
async def get_angular_velocity_body_status():
async for attitude_angular_velocity_body in system.telemetry.attitude_angular_velocity_body():
print(attitude_angular_velocity_body)
async def get_attitude_euler_status():
async for attitude in system.telemetry.attitude_euler():
print(attitude)
async def get_battery_status():
async for battery in system.telemetry.battery():
print(battery)
async def get_flight_mode_status():
async for flight_mode in system.telemetry.flight_mode():
print(flight_mode)
async def get_gps_info_status():
async for gps_info in system.telemetry.gps_info():
print(gps_info)
async def get_health_status():
async for health in system.telemetry.health():
print(health)
async def get_health_all_ok_status():
async for health_all_ok in system.telemetry.health_all_ok():
print(health_all_ok)
async def get_home_status():
async for home in system.telemetry.home():
print(home)
async def get_in_air_status():
async for in_air in system.telemetry.in_air():
print(in_air)
async def get_landed_state_status():
async for landed_state in system.telemetry.landed_state():
print(landed_state)
async def get_position_status():
async for position in system.telemetry.position():
print(position)
async def get_velocity_ned_status():
async for velocity_ned in system.telemetry.velocity_ned():
print(velocity_ned)
async def main():
await system.connect("serial:///dev/ttyUSB0:921600")
asyncio.create_task(check_connection_state())
asyncio.create_task(get_armed_status())
asyncio.create_task(get_angular_velocity_body_status())
asyncio.create_task(get_attitude_euler_status())
asyncio.create_task(get_battery_status())
asyncio.create_task(get_flight_mode_status())
asyncio.create_task(get_gps_info_status())
asyncio.create_task(get_health_status())
asyncio.create_task(get_health_all_ok_status())
asyncio.create_task(get_home_status())
asyncio.create_task(get_in_air_status())
asyncio.create_task(get_position_status())
asyncio.create_task(get_velocity_ned_status())
if __name__ == "__main__":
loop = asyncio.get_event_loop()
try:
loop.create_task(main())
loop.run_forever()
finally:
loop.stop()
loop.close()
Could someone provide some insight as to why this is occurring?