Some functions like goto function or speed setting function are limited because they are GPS dependent. GPS is not available for an underwater robot. If I change the vehicle mode to "ALT_HOLD", the arm_and_takeoff function will work:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22from dronekit import connect, VehicleMode, LocationGlobal, LocationGlobalRelative from pymavlink importmavutil # Needed for command message definitions import time import math vehicle =connect('/dev/ttyACM0', wait_ready=True) defarm_and_takeoff(aTargetAltitude): print"Arming motors" # Coptershould arm in GUIDED mode vehicle.mode = VehicleMode("ALT_HOLD") vehicle.armed = True print"Taking off!" vehicle.simple_takeoff(aTargetAltitude) # Take off to target altitude whileTrue: print " Altitude: ",vehicle.location.global_relative_frame.alt if vehicle.location.global_relative_frame.alt>=aTargetAltitude*0.95: print "Reached target altitude" break time.sleep(1) arm_and_takeoff(5) print("Completed")
The battery connected to Ardusub cannot be sensed. I don't know why as the battery works well when it connects to the ArduCopter.
Battery: Voltage=0.0,current=None, level=None.
Note:A value of None foran attribute member indicates that the value has not yet been populated fromthe vehicle. For example, before GPS lock Vehicle.gps_0 will return a GPSInfo with None valuesfor eph, satellites_visible etc. Attributes will also return None if theassociated hardware is not present on the connected device.
Building ArduPilot for Pixhawk/PX4 on Mac with Make (Download the ArduCopter in the BlueROV)http://ardupilot.org/dev/docs/building-px4-with-make-on-mac.html
In the terminal:
1
2
3
4
5
6
7
8
9
10brew tap PX4/homebrew-px4 brew update brew install genromfs brew install gcc-arm-none-eabi brew install gawk sudo easy_install pip sudo pip installpyserial mkdir -p px4 cd px4 git clone --recursive https://github.com/ArduPilot/ardupilot.git
Set the current path to:/Users/apple/px4/ardupilot/ArduCopter
1
2make clean make pix-v2
https://www.bluerobotics.com/forums/topic/autonomous-operation/
The Vehicle.mode, Vehicle.armed , Vehicle.airspeed and Vehicle.groundspeed, attributes can allbe “directly” written (Vehicle.home_location can also bedirectly written, but has special considerations that are discussed below).
Commands to change a value are not guaranteed to succeed (oreven to be received) and code should be written with this in mind. For example, the code snippet below polls the attribute values to confirm they have changed before proceeding.
1
2
3
4
5
6
7vehicle.mode = VehicleMode("GUIDED") while not vehicle.mode.name=='GUIDED' and not vehicle.armed and not api.exit: time.sleep(1) vehicle print " Getting ready to take off ..." vehicle.armed =True
Observing attribute changes:
http://python.dronekit.io/guide/vehicle_state_and_parameters.htmlYou can observe any of the vehicle attributes and monitor forchanges without the need for polling.
Listeners (“observer callback functions”) are invoked differentlybased on the type of observed attribute. Attributes that represent sensorvalues or other “streams of information” are updated whenever a message isreceived from the vehicle. Attributes which reflect vehicle “state” are onlyupdated when their values change (for example Vehicle.system_status, Vehicle.armed,and Vehicle.mode).
Callbacks are added using Vehicle.add_attribute_listener() ortheVehicle.on_attribute()decorator method. The main difference between these methods is that onlyattribute callbacks added with Vehicle.add_attribute_listener() canbe removed (see remove_attribute_listener())
- The observer callback function is invoked with thefollowing arguments:
- self - the associated Vehicle. This may be compared to a global vehicle handle to implement vehicle-specific callback handling (if needed).
- attr_name - the attribute name. This can be used to infer which attribute has triggered if the same callback is used for watching several attributes.
- value - the attribute value (so you don’t need to re-query the vehicle object)
The code snippet below shows how to add (and remove) a callback function to observe changes in Vehicle.location.global_frame using Vehicle.add_attribute_listener(). The two second sleep() is required because otherwise the observer might be removed before the the callback is first run.
1
2
3
4
5
6
7
8
9
10
11
12
13
14#Callback to print the location in globalframes. 'value' is the updated value def location_callback(self,attr_name, value): print "Location (Global): ", value # Add a callback `location_callback` for the `global_frame`attribute. vehicle.add_attribute_listener('location.global_frame', location_callback) # Wait 2s so callback can be notified before the observer is removed time.sleep(2) # Remove observer - specifying the attribute and previouslyregistered callback function vehicle.remove_message_listener('location.global_frame', location_callback)
Note: The example above adds a listener on Vehicle to for attribute name 'location.global_frame'You can alternatively add (and remove) alistenerVehicle.locationfor the attribute name 'global_frame'. Both alternatives are shown below:
1
2vehicle.add_attribute_listener('location.global_frame', location_callback) vehicle.location.add_attribute_listener('global_frame', location_callback)
The example below shows how you can declare an attribute callback using the Vehicle.on_attribute() decorator function.
1
2
3
4
5
6
7
8
9last_rangefinder_distance = 0 @vehicle.on_attribute('rangefinder') def rangefinder_callback(self, attr_name): #attr_name not used here. globallast_rangefinder_distance if last_rangefinder_distance == round(self.rangefinder.distance, 1): return last_rangefinder_distance = round(self.rangefinder.distance, 1) print " Rangefinder(metres): %s" % last_rangefinder_distance
The examples above show how you can monitor a single attribute. You can pass the special name (‘*‘) to specify a callback that will be called for any/all attribute changes:
1
2
3
4
5
6
7
8
9
10# Demonstrate getting callback on any attribute change def wildcard_callback(self, attr_name, value): print " CALLBACK: (%s): %s" % (attr_name,value) print "nAdd attribute callback detecting any attribute change" vehicle.add_attribute_listener('*', wildcard_callback) print " Wait 1s so callback invoked before observer removed" time.sleep(1) print " Remove Vehicle attribute observer" #Remove observer added with `add_attribute_listener()` vehicle.remove_attribute_listener('*', wildcard_callback)
最后
以上就是端庄季节最近收集整理的关于BlueROV-8: Functions to Drive the Vehicle的全部内容,更多相关BlueROV-8:内容请搜索靠谱客的其他文章。
发表评论 取消回复