From a vanilla install, attempting to run the code
def init(self):
“”“Constructor.”“”
mavutil.set_dialect(“ardupilotmega”)
# Create the connection
self.master = mavutil.mavlink_connection(‘/dev/serial/by-id/usb-3D_Robotics_PX4_FMU_v2.x_0-if00’)
# Wait a heartbeat before sending commands
self.master.wait_heartbeat()# Set all rc chans pwm to PWM_NEUTRAL_CENTER before arming: self.rc_channels = [ self.PWM_NEUTRAL_CENTER ] * 8 self.master.mav.rc_channels_override_send(self.master.target_system, self.master.target_component, *self.rc_channels)
yields this following result:
(venv) pi@raspberrypi:~/projects/underquad/controller$ python
./controller.py Traceback (most recent call last):
File “./controller.py”, line 244, in
controller = UnderQuadController()
File “./controller.py”, line 79, in init
self.master = mavutil.mavlink_connection(‘/dev/serial/by-id/usb-3D_Robotics_PX4_FMU_v2.x_0-if00’)
File “/home/pi/projects/underquad/controller/venv/local/lib/python2.7/site-packages/pymavlink/mavutil.py”, line 1251, in mavlink_connection
return mavserial(device, baud=baud, source_system=source_system, source_component=source_component, autoreconnect=autoreconnect, use_native=use_native)
File “/home/pi/projects/underquad/controller/venv/local/lib/python2.7/site-packages/pymavlink/mavutil.py”, line 786, in init
import serial
ImportError: No module named serial
This means that the python instance is not recognizing the serial library that was installed with apt-get.
After running
pip install serial
And re-running the code, we get the following error.
Traceback (most recent call last):
File “./controller.py”, line 244, in
controller = UnderQuadController()
File “./controller.py”, line 79, in init
self.master = mavutil.mavlink_connection(‘/dev/serial/by-id/usb-3D_Robotics_PX4_FMU_v2.x_0-if00’)
File “/home/pi/projects/underquad/controller/venv/local/lib/python2.7/site-packages/pymavlink/mavutil.py”, line 1251, in mavlink_connection
return mavserial(device, baud=baud, source_system=source_system, source_component=source_component, autoreconnect=autoreconnect, use_native=use_native)
File “/home/pi/projects/underquad/controller/venv/local/lib/python2.7/site-packages/pymavlink/mavutil.py”, line 795, in init
self.port = serial.Serial(self.device, 1200, timeout=0,
AttributeError: ‘module’ object has no attribute ‘Serial’