Home        Store        Docs        Blog

Raspberry Pi 3 ArduCopter V3.2.1 connection


Hello, im trying to connect my raspberry pi 3 v1.2 to ArduCopter V3.2.1 through serial GPIO. I made the connection and follow some instructions on youtube and got into somewhere. i run a script on pi to get telemetry data in a loop but it gives mi this

Connecting with the UAV

CRITICAL:autopilot:ArduCopter V3.2.1 (36b405fb)
CRITICAL:autopilot:Frame: QUAD

im using ttyS0 57600 baudrate.

my aim is to use ArduCopter V3.2.1 as my flight controller and run my computer vision scripts on it. can you help me?

code i used is
This script will introduce multiple things:

Run the simulator inside dronekit
Read and handle telemetry from the UAV
Read and change parameters

from dronekit import connect, VehicleMode
import time

#— Start the Software In The Loop (SITL)
#import dronekit_sitl

connection_string = “/dev/ttyS0”
baud_rate = 57600
#— Now that we have started the SITL and we have the connection string (basically the ip and udp port)…

print(">>>> Connecting with the UAV <<<")
vehicle = connect(connection_string, baud = baud_rate, wait_ready=True) #- wait_ready flag hold the program untill all the parameters are been read (=, not .)

#-- Read information from the autopilot:
#- Version and attributes
print(‘Autopilot version: %s’%vehicle.version)

#- Does the firmware support the companion pc to set the attitude?
print(‘Supports set attitude from companion: %s’%vehicle.capabilities.set_attitude_target_local_ned)

#- Read the actual position
print(‘Position: %s’% vehicle.location.global_relative_frame)

#- Read the actual attitude roll, pitch, yaw
print(‘Attitude: %s’% vehicle.attitude)

#- Read the actual velocity (m/s)
print(‘Velocity: %s’%vehicle.velocity) #- North, east, down

#- When did we receive the last heartbeat
print(‘Last Heartbeat: %s’%vehicle.last_heartbeat)

#- Is the vehicle good to Arm?
print(‘Is the vehicle armable: %s’%vehicle.is_armable)

#- Which is the total ground speed? Note: this is settable
print(‘Groundspeed: %s’% vehicle.groundspeed) #(%)

#- What is the actual flight mode? Note: this is settable
print(‘Mode: %s’% vehicle.mode.name)

#- Is the vehicle armed Note: this is settable
print(‘Armed: %s’%vehicle.armed)

#- Is thestate estimation filter ok?
print(‘EKF Ok: %s’%vehicle.ekf_ok)

#----- Adding a listener
#-- dronekit updates the variables as soon as it receives an update from the UAV
#-- you can define a callback function for predefined messages or define one for
#-- any mavlink message

def attitude_callback(self, attr_name, value):

print(“Adding an attitude listener”)
vehicle.add_attribute_listener(‘attitude’, attitude_callback) #-- message type, callback function

#— Now we print the attitude from the callback for 5 seconds, then we remove the callback
vehicle.remove_attribute_listener(‘attitude’, attitude_callback) #(.remove)

#— You can create a callback even with decorators, check the documentation out for more details

print(“Maximum Throttle: %d”%vehicle.parameters[‘THR_MIN’])

#-- You can read and write the parameters
vehicle.parameters[‘THR_MIN’] = 50
print(“Maximum Throttle: %d”%vehicle.parameters[‘THR_MIN’])

#— Now we close the simulation




(Patrick José Pereira) #2


You should take a look in ArduPilot/ArduCopter forum, this one is for ArduSub and related :wink: