Hi,
I am using Jetson Nano and Pixhawk. Pixhawk is connected with Jetson Nano via USB Cable, on the USB port of Jetson Nano and Micro USB port on Pixhawk. I wrote the codes using Jupyter Notebook with Python 3.8.
After typing this command:
import serial
from pymavlink import mavutil
serial_port = ‘/dev/ttyACM0’
connection = mavutil.mavlink_connection(serial_port)
I didn’t get any errors so they connected properly.
But I got an error when I wrote this command to trigger the servo motor connected to the Pixhawk via the Jetson Nano:
import time
import os
import platform
import sys
from dronekit import connect, VehicleMode,LocationGlobal,LocationGlobalRelative
from pymavlink import mavutil
############DRONEKIT#################
vehicle = connect(‘/dev/ttyACM0’,wait_ready=True)
servo=9
high=1900
low=1100
#########FUNCTIONS###########
def controlServo(servo_number,pwm_value):
msg = vehicle.message_factory.command_long_encode(
0,
0,
mavutil.mavlink.MAV_CMD_DO_SET_SERVO,
0,
servo_number,
pwm_value,
0,
0,
0,
0,
0)
vehicle.send_mavlink(msg)
###########Example execution#####
controlServo(servo,high)
time.sleep(1)
controlServo(servo,low)
#time.sleep(1)
This was the error message:
APIException Traceback (most recent call last)
Cell In[3], line 11
7 from pymavlink import mavutil
8 #############################
9 ############DRONEKIT#################
10 # /dev/ttyTHS1 veya /dev/ttyACM0
—> 11 vehicle = connect(‘/dev/ttyACM0’,wait_ready=True)
12 servo=9
13 high=1900
File ~/newenv/lib/python3.8/site-packages/dronekit/init.py:3166, in connect(ip, _initialize, wait_ready, timeout, still_waiting_callback, still_waiting_interval, status_printer, vehicle_class, rate, baud, heartbeat_timeout, source_system, source_component, use_native)
3163 vehicle._autopilot_logger.addHandler(ErrprinterHandler(status_printer))
3165 if _initialize:
→ 3166 vehicle.initialize(rate=rate, heartbeat_timeout=heartbeat_timeout)
3168 if wait_ready:
3169 if wait_ready is True:
File ~/newenv/lib/python3.8/site-packages/dronekit/init.py:2275, in Vehicle.initialize(self, rate, heartbeat_timeout)
2273 break
2274 if not self._handler._alive:
→ 2275 raise APIException(‘Timeout in initializing connection.’)
2277 # Register target_system now.
2278 self._handler.target_system = self._heartbeat_system
APIException: Timeout in initializing connection.
How can I solve this problem?
Thanks!