Trying to control ArduCopter in Guided Mode using mavutil

Hi everyone, I am new to the forums. I am trying to control my Copter in Guided Mode, particularly on how to control the copter’s velocity through pymavlink’s mavutil API. Now I saw some guided mode examples in dronekit-python, but I am not using drone-kit since it’s not been developed for a very long time. I although have found documents that contains the messages that are required to be sent to MAVLINK (under the copter commands - guided mode). I am just unable to imply how to send these messages through pymavlink’s mavutil API. Can anybody help me on how to command the copter?

I recommend you read and use the pymavlink pull request form @khancyr.
Search it in GitHub - ArduPilot/pymavlink: python MAVLink interface and utilities

thanks for recommending this example, I’ll go through it. However, this example solely explains how to create waypoints and do a mission. I was hoping to find a method to control my copter’s velocity particularly in x,y,z directions.

You may find the commands here: Copter Commands in Guided Mode — Dev documentation

Example:

from pymavlink import mavutil

connection = mavutil.mavlink_connection('udp:127.0.0.1:14560')      # Or your connection port

# Give command to move with x and y velocities = vx and vy, respectively. 
# vx = 5
# vy = 2
connection.mav.send(
                    mavutil.mavlink.MAVLink_set_position_target_global_int_message(
                                10, connection.target_system, connection.target_component,  
                                mavlink.MAV_FRAME_GLOBAL, int(0b010111000111), 
                                0,0,vx,vy,0,0,0,0,0,0
                                )
                    )
1 Like

Will try this out and get back

I tried this command, seems like I keep getting this error
TypeError: send() takes from 2 to 3 positional arguments but 9 were given

then i tried to send the command as a message,
like
message = mavutil.mavlink.SET_POSITION_TARGET_GLOBAL_INT( # the message type that need to be sent
10, # sender’s system time in milliseconds since boot
the_connection.target_system, #target system ID
the_connection.target_component, # target componet ID
# 0, #ID of command to send or just 0
the_connection.MAV_FRAME_GLOBAL, # Coordinate frame (check Copter Commands in Guided Mode — Dev documentation for Valid options )
int(0b110111000111), #type_mask to be used, using velocity mask, for which fields need to be ignored by the vehicle
0, # lat_int
0, # long_int
0, # altitude in meters above frame of reference
vx, # (X velocity in m/s) +ve in North
0, # (Y velocity in m/s) +ve is East
vz, # (Z velocity in m/s) +ve is Down
0, # X acc
0, # Y acc
0, # Z acc
0, # yaw or heading in radians (0 is fwd)
0, # yaw rate in rad/s

)
and then sent the message through connection.mav.send(message)
to which i got error
TypeError: ‘int’ object is not callable