(tested)
1. 新增 ros2 接收 SET_POSITION_TARGET_LOCAL_NED 功能, 因應新增 MavPositionTargetGlobalInt.srv 的介面定義檔, 並相應新增使用者的外層包裝 navigation.py 2. 改善 ros2 service 的 response ack 數值對應, 新增 ackEnum.py 3. 改善 longCommand.py 內的呼叫層次, 把 longCommand 相關整合到同樣的 class 下, 僅以 def function 區分內部套用那種 MAV_CMD 4. 新增 example_position_goto.py, example_takeoff_land.py 作為使用範例 ( land.py arm_disarm.py ... 這些下個版本會被刪除) 5. 剩下就是一些註解的修正與更新chiyu
parent
44d53f51fb
commit
eb2f0af58e
@ -0,0 +1,36 @@
|
|||||||
|
# Request
|
||||||
|
uint8 target_sysid
|
||||||
|
uint8 target_compid
|
||||||
|
|
||||||
|
uint32 time_boot_ms # ms since system boot, 一般用 0 讓飛控自己填
|
||||||
|
uint8 coordinate_frame # MAV_FRAME_*
|
||||||
|
uint16 type_mask # POSITION_TARGET_TYPEMASK bitmask
|
||||||
|
int32 lat_int # 1e7 * latitude (deg)
|
||||||
|
int32 lon_int # 1e7 * longitude (deg)
|
||||||
|
float32 alt # altitude (m)
|
||||||
|
float32 vx # X velocity (m/s)
|
||||||
|
float32 vy # Y velocity (m/s)
|
||||||
|
float32 vz # Z velocity (m/s)
|
||||||
|
float32 afx # X acceleration or force (m/s^2)
|
||||||
|
float32 afy # Y acceleration or force (m/s^2)
|
||||||
|
float32 afz # Z acceleration or force (m/s^2)
|
||||||
|
float32 yaw # yaw (rad)
|
||||||
|
float32 yaw_rate # yaw rate (rad/s)
|
||||||
|
float32 timeout_sec # 等待 POSITION_TARGET_GLOBAL_INT 回應的時間上限
|
||||||
|
---
|
||||||
|
# Response
|
||||||
|
string message
|
||||||
|
uint8 ack_result
|
||||||
|
uint32 r_time_boot_ms
|
||||||
|
uint16 r_type_mask
|
||||||
|
int32 r_lat_int
|
||||||
|
int32 r_lon_int
|
||||||
|
float32 r_alt
|
||||||
|
float32 r_vx
|
||||||
|
float32 r_vy
|
||||||
|
float32 r_vz
|
||||||
|
float32 r_afx
|
||||||
|
float32 r_afy
|
||||||
|
float32 r_afz
|
||||||
|
float32 r_yaw
|
||||||
|
float32 r_yaw_rate
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
'''
|
||||||
|
單獨出來定義回傳碼的意義
|
||||||
|
若跟飛控韌體有正常的通訊 (無論是否被拒絕) 則以 mavlink 定義的結果回傳
|
||||||
|
若跟飛控韌體無法通訊 才使用這邊的錯誤代碼
|
||||||
|
所以要避開重疊的號碼
|
||||||
|
|
||||||
|
這邊備註 Mavlink 的 MAV_RESULT 參數意義
|
||||||
|
0 : 封包正常接受並執行
|
||||||
|
1 : 封包正常接受 但是正在忙不執行 需要等待後重試
|
||||||
|
4 : 封包正常接受 但是載具的狀態異常 不執行
|
||||||
|
|
||||||
|
2 : 封包不正常 參數可能給錯了
|
||||||
|
3 : 封包不正常 根本認不出是啥
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
from enum import IntEnum
|
||||||
|
|
||||||
|
class serviceAckResult(IntEnum):
|
||||||
|
MAVLINK_TIMEOUT = 51 # mavlink communication timeout
|
||||||
|
|
||||||
|
MAVLINK_SEND_BUT_NO_EXP_STEAM = 30 # some messages will not have obviously ack, so monitering feature message. however, we do NOT get the feature message. ex. 85/86 pair
|
||||||
|
|
||||||
|
MAVLINK_BUSY = 53 # there already has a command being execution for this sysid, try later
|
||||||
|
MAVLINK_DEV_NOTFOUND = 54 # this sysid not fount
|
||||||
|
|
||||||
|
UNKNOWN = 90 # i did not capture this error, try read the logs
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,64 @@
|
|||||||
|
|
||||||
|
from fc_network_apps import CommandLongClient
|
||||||
|
import time
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# Equivalent to:
|
||||||
|
# ros2 service call /fc_network/vehicle/send_command_long ... param1:1 param2:4
|
||||||
|
commandAPI = CommandLongClient()
|
||||||
|
|
||||||
|
result = commandAPI.change_mode(
|
||||||
|
target_sysid=3,
|
||||||
|
target_compid=0,
|
||||||
|
base_mode=1.0,
|
||||||
|
custom_mode=4.0,
|
||||||
|
timeout_sec=3.0,
|
||||||
|
)
|
||||||
|
|
||||||
|
print("=== change mode result ===")
|
||||||
|
print(f"success : {result.success}")
|
||||||
|
print(f"ack_result: {result.ack_result}")
|
||||||
|
print(f"message : {result.message}")
|
||||||
|
|
||||||
|
time.sleep(3)
|
||||||
|
|
||||||
|
result = commandAPI.arm_disarm(
|
||||||
|
target_sysid=3,
|
||||||
|
target_compid=0,
|
||||||
|
arm = True,
|
||||||
|
)
|
||||||
|
|
||||||
|
print("=== change mode result ===")
|
||||||
|
print(f"success : {result.success}")
|
||||||
|
print(f"ack_result: {result.ack_result}")
|
||||||
|
print(f"message : {result.message}")
|
||||||
|
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
result = commandAPI.takeoff(
|
||||||
|
target_sysid=3,
|
||||||
|
target_compid=0,
|
||||||
|
altitude_m = 30.0,
|
||||||
|
)
|
||||||
|
|
||||||
|
print("=== change mode result ===")
|
||||||
|
print(f"success : {result.success}")
|
||||||
|
print(f"ack_result: {result.ack_result}")
|
||||||
|
print(f"message : {result.message}")
|
||||||
|
|
||||||
|
# time.sleep(20)
|
||||||
|
|
||||||
|
# result = commandAPI.land(
|
||||||
|
# target_sysid=3,
|
||||||
|
# target_compid=0,
|
||||||
|
# )
|
||||||
|
|
||||||
|
# print("=== change mode result ===")
|
||||||
|
# print(f"success : {result.success}")
|
||||||
|
# print(f"ack_result: {result.ack_result}")
|
||||||
|
# print(f"message : {result.message}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in New Issue