BlueROV-7: Keep Learning Dronekit

2023-05-16

The motors can spin now by using the following program:

from dronekit import connect,VehicleMode
import sys
import time
 
# Connect to UDP endpoint (andwait for default attributes to accumulate)
target = sys.argv[1] iflen(sys.argv) >= 2 else 'udpin:0.0.0.0:14550'
print 'Connecting to ' + target +'...'
vehicle =connect('/dev/tty.usbmodem1', wait_ready=True)
vehicle.mode =VehicleMode("ALT_HOLD")
 
print " Ch4: %s" %vehicle.channels['3']
vehicle.channels.overrides['3'] =1670
vehicle.flush()
print "should berunning"
time.sleep(5);
vehicle.channels.overrides['3'] =None
vehicle.flush()
 
vehicle.close()
print "Done."

But the vehicle can connect to the laptop only once, and after one successful connection, connection will have problems:

>>> Link timeout, no heartbeat in last 5seconds

>>> No heartbeat in 30 seconds, aborting.

There is no such solution on Google.

The problem appears on Mac system. If I use Raspberry Pi (Linux), there is no such problem.

Butin Raspberry Pi, the simulator has some errors:

OSError: [Errno 8] Exec format error

As a result, I will use Mac to run the simulator program, and use Raspberry Pi torun program towards actual vehicle.


Some functions that I will use:

Cannot use Vehicle.simple_goto(), because it belongs to Position Control, and there is no GPS sensor in the vehicle.


Velocity Controlis available:http://python.dronekit.io/guide/copter/guided_mode.html

Controlling vehicle movement using velocity is much smoother than using position when there are likely to be many updates (for example when tracking moving objects).

The function send_ned_velocity() below generates a SET_POSITION_TARGET_LOCAL_NED MAVLink message which is used to directly specify the speed components of the vehicle in the MAV_FRAME_LOCAL_NED frame (relative to home location). The message is re-sent every second for the specified duration.

def send_ned_velocity(velocity_x, velocity_y, velocity_z, duration):
    """
    Move vehicle in direction based on specified velocity vectors.
    """
    msg = vehicle.message_factory.set_position_target_local_ned_encode(
        0,      # time_boot_ms (not used)
        0,0,   # target system, target component
        mavutil.mavlink.MAV_FRAME_LOCAL_NED,# frame
        0b0000111111000111,# type_mask (only speeds enabled)
        0,0,0,# x, y, z positions (not used)
        velocity_x, velocity_y, velocity_z,# x, y, z velocity in m/s
        0,0,0,# x, y, z acceleration (not supported yet, ignored in GCS_Mavlink)
        0,0)   # yaw, yaw_rate (not supported yet, ignored in GCS_Mavlink)
 
# send command to vehicle on 1 Hz cycle
    for x in range(0,duration):
        vehicle.send_mavlink(msg)
        time.sleep(1)

The function send_ned_velocity() below generates a SET_POSITION_TARGET_LOCAL_NED MAVLink message which is used to directly specify the speed components of the vehicle in the MAV_FRAME_LOCAL_NED frame (relative to home location). The message is re-sent every second for the specified duration.

The type_mask parameter is a bitmask that indicates which of the other parameters in the message are used/ignored by the vehicle (0 means that the dimension is enabled, 1 means ignored). In the example the value 0b0000111111000111 is used to enable the velocity components.

In the MAV_FRAME_LOCAL_NED the speed components velocity_x and velocity_y are parallel to the North and East directions (not to the front and side of the vehicle). The velocity_z component is perpendicular to the plane of velocity_x and velocity_y, with a positive value towards the ground, following the right-hand convention. For more information about the MAV_FRAME_LOCAL_NED frame of reference, see this wikipedia article on NED.

Note: (From Copter 3.3 the vehicle will stop moving if a new message is not received in approximately 3 seconds. Prior to Copter 3.3 the message only needs to be sent once, and the velocity remains active until the next movement command is received. The example code works for both cases!)

The code fragment below shows how to call this method:

# Set up velocity mappings
# velocity_x > 0 => fly North
# velocity_x < 0 => fly South
# velocity_y > 0 => fly East
# velocity_y < 0 => fly West
# velocity_z < 0 => ascend
# velocity_z > 0 => descend
SOUTH=-2
UP=-0.5  #NOTE: up is negative!
#Fly south and up.
send_ned_velocity(SOUTH,0,UP,DURATION)

Setting the Yaw: What's the corresponding sensor?
The vehicle “yaw” is the direction that the vehicle is facing in the horizontal plane. On Copter this yaw need not be the direction of travel (though it is by default).

arm_and_takeoff

I can use Override Channel to start motors, but as the official webpage says, this way to let the motors spin is highly dis-commended. 
Up till now, I cannot use function like send_ned_velocity to control the motors.

http://python.dronekit.io/examples/channel_overrides.htm

The values of the first four channels map to the main flightcontrols: 1=Roll, 2=Pitch, 3=Throttle, 4=Yaw (the mapping is defined in RCMAP_ parameters in Plane,Copter,Rover).

The remaining channel values are configurable, and their purpose can be determined using the RCn_FUNCTION parameters. In general a value of 0 set for a specific RCn_FUNCTION indicates that the channel can be mission controlled (i.e. it will not directly be controlled by normal autopilot code).


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

BlueROV-7: Keep Learning Dronekit 的相关文章

随机推荐