swarmae包

class swarmae.SwarmAEActor.SwarmAEActor(node_id, health, energy, color, size)

基类:object

角色实例抽象父类,派生出Node、Sensor和Weapon等实例类,并提供通用的相关基础信息接口

参数:
  • node_id – 节点唯一ID

  • health – 生命值

  • energy – 能源值

  • color – 颜色

  • size – 尺寸

get_color()

获取颜色

返回:

颜色

返回类型:

dict

返回示例:

{'a': 1, 'b': 6.966855, 'g': 12.675285, 'r': 12.28386}
get_energy()

获取能源

返回:

能量

返回类型:

float

get_health()

获取生命值

返回:

生命值

返回类型:

float

get_node_id()

获取节点id

返回:

节点id

返回类型:

int

get_size()

获取尺寸

返回:

尺寸

返回类型:

dict

返回示例:

{'x': 3.0, 'y': 1.2999999523162842, 'z': 1.5}
class swarmae.SwarmAEChannel.SwarmAEChannel(topic, channel_name, is_keepalived, lifetime, is_available)

基类:object

通讯通道实例类,提供通讯的相关信息接口

参数:
  • topic – 会话主题

  • channel_name – 通道名称

  • is_keepalived – 是否心跳监测

  • lifetime – 生命周期时长

  • is_available – 是否可用

get_channel_nodes(node_id)

获取通讯节点接口 根据节点ID获取可通讯的节点信息

参数:

node_id – 节点id

返回:

node_ids-可通讯节点ids(唯一id数组), count-可通讯节点总数, channel_name_通道名称, topic-会话主题, code-成功状态码,

frame_timestamp-当前帧时间戳, remain_lifetime-剩余生命周期时常, is_available-是否可用

receive_message(node_id, frame_timestamp, topic)

获取协同信息接口 获取消息接口

参数:
  • node_id – 发送方节点id

  • frame_timestamp – 当前帧时间戳

  • topic – 会话主题

返回:

code-成功状态码, msg_data-数据信息(字节流:ros或prototbuff), frame_timestamp-返回帧时间戳

send_message(node_id, msg_data, frame_timestamp, topic)

发送协同信息接口 发送消息接口

参数:
  • node_id (int) – 发送方节点id

  • msg_data – 数据信息(字节流:ros或prototbuff)

  • frame_timestamp (int) – 当前帧时间戳

  • topic (int) – 会话主题

返回:

code-成功状态码, frame_timestamp-返回帧时间戳

返回类型:

int, int

class swarmae.SwarmAEClient.SwarmAEClient(ue_ip=None, ue_port=None)

基类:object

节点客户端,提供连接和注册初始化工作

get_world()

获取当前仿真世界

返回:

返回帧时间戳, 仿真世界, 成功状态码

返回类型:

int, SwarmAEWorld, int

register_node(node_type, node_name, node_no, frame_timestamp)

注册节点接入平台接口

根据节点信息向平台注册接入,接入成功返回注册节点.

参数:
  • node_type (str) – 节点类型,四轮车、四旋翼

  • node_name (str) – 节点名称

  • node_no (int) – 节点编号(队伍中编号),编号从1开始

  • frame_timestamp (int) – 当前帧时间戳

返回:

返回帧时间戳, 节点, 成功状态码

返回类型:

int, SwarmAENode, int

示例(无人车):

# 注册无人车
timestamp, node, code = client.register_node(
  node_type="四轮车", node_name="节点1", node_no=1, frame_timestamp=int(round(time.time() * 1000))
)
if code == 200:
  # 注册成功,则可使用 node
示例(无人机):

# 注册无人机
timestamp, node, code = client.register_node(
  node_type="四旋翼", node_name="节点1", node_no=1, frame_timestamp=int(round(time.time() * 1000))
)
if code == 200:
  # 注册成功,则可使用 node
class swarmae.SwarmAEConnect.SwarmAEConnect

基类:object

通讯连接实例类,提供通讯的相关信息接口

create_channel(node_ids)

建立节点通讯连接接口 建立节点通讯通道

警告

接口暂未提供

:param node_ids:节点ids(唯一id数组) :return: swarmae_channel-通道, code-成功状态码, frame_timestamp-当前帧时间戳

release_channel(swarmae_channel)

回收节点通讯通道接口 回收节点通讯通道

警告

接口暂未提供

:param swarmae_channel:通道 :return: frame_timestamp-当前帧时间戳, code-状态码

swarmae.SwarmAEMulticast.SwarmMulticast(*args, **kw)
swarmae.SwarmAEMulticast.singleton(cls, *args, **kw)
class swarmae.SwarmAENode.SwarmAENode(actor_info, actor, node_type, node_name, node_no, rgb, lidar)

基类:SwarmAEActor

节点实例类,继承SwarmAEActor类。提供获取节点的相关信息接口

apply_control(throttle, steer, brake, hand_brake, gear)

控制车辆行为接口 - 现版本SDK暂未提供,后续SDK更新支持

参数:
  • throttle – 油门

  • steer – 转向

  • brake – 刹车

  • hand_brake – 手刹

  • gear – 档位

返回:

frame_timestamp-响应帧时间戳, code-返回状态码

返回类型:

int, int

control_kinetic_full(elevator_angle, direct_angle, aileron_angle, flap_angle, throttle, frame_timestamp)

动力学控制信息接口(复杂飞控,按舵角、油门等) 动力学控制飞机飞行,目前按照目标点设置

警告

接口暂未提供

参数:
  • elevator_angle – 升降舵偏角(下偏为正)

  • direct_angle – 方向舵偏角(左偏为正)

  • aileron_angle – 副翼舵偏角(左上右下为正)

  • flap_angle – 襟翼舵偏角(下偏为正)

  • throttle – 油门

  • frame_timestamp – 当前帧时间戳

返回:

code-返回状态码, frame_timestamp-返回帧时间戳

control_kinetic_simply(x, y, z, v, frame_timestamp)

动力学控制信息接口(简单飞控,按目标点) 动力学控制飞机飞行,目前按照目标点设置从 出生点 往 指定位置飞行距离,例如出生点为10,10,10 调用该接口即为飞机向10+x,10+y,10+z飞行

参数:
  • x (float) – N,北向(米)

  • y (float) – E,东向(米)

  • z (float) – U,天向(米)

  • v (float) – GS,地速(米/秒)

  • frame_timestamp – 当前帧时间戳

返回:

code-返回状态码, frame_timestamp-返回帧时间戳

返回类型:

int, int

control_kinetic_simply_global(x, y, z, v, frame_timestamp)

动力学控制信息接口(简单飞控,按目标点) 动力学控制飞机飞行,目前按照目标点设置

参数:
  • x (float) – N,北向(米)

  • y (float) – E,东向(米)

  • z (float) – U,天向(米)

  • v (float) – GS,地速(km/h)

  • frame_timestamp – 当前帧时间戳

返回:

code-返回状态码, frame_timestamp-返回帧时间戳

返回类型:

int, int

control_vehicle(throttle)

设置车辆油门数据接口 设置当前车辆油门信息

参数:

throttle (float) – 油门 范围:[-1.0, 1.0] 默认:0.0, 负为倒车

返回:

frame_timestamp-响应帧时间戳, code-返回状态码

返回类型:

int, int

detect_hostile_list()

获取侦察范围内侦测到的敌人信息列表

返回:

侦察的敌人信息列表

返回类型:

list

示例返回:

>>> [('imv', Transform(Location(x=-880.337891, y=455.569061, z=486.440033), Rotation(pitch=0.272791, yaw=0.010868, roll=0.261231)))]
get_attitude()

获取当前节点的姿态信息

返回:

偏航角(yaw), 俯仰角(pitch), 翻滚角(roll), 朝向(heading), 当前帧时间戳

:rtype; float, float, float, str, int

get_damage()

获取节点中弹信息接口 获取当前节点的中弹信息 :return: damage-损伤程度, is_hit-是否中弹, frame_timestamp-当前帧时间戳

get_fire_angle()

获取攻击角度

返回:

z轴, y轴

返回类型:

float, float

get_fire_angle_range()

获取攻击范围

返回:

最小z轴, 最大z轴, 最小y轴, 最大y轴

返回类型:

float, float, float, float

get_health()

获取节点生命值信息接口 获取当前节点的生命值信息

返回:

current_health-当前生命值 frame_timestamp-当前帧时间戳

get_kinetic_data()

获取飞行数据接口 获取当前飞机飞行数据状态信息

警告

接口暂未提供

返回:

elevator_angle-升降舵偏角 direct_angle-方向舵偏角 aileron_angle-副翼舵偏角 flap_angle-襟翼舵偏角 throttle-油门 h-海拔高度 lat-纬度 lon-经度

get_kinetic_data_simply()

获取飞行数据接口 获取当前飞机飞行数据状态信息

返回:

x: N,北向(米), y: E,东向(米), z: U,天向(米), pitch: 俯仰角, roll: 横倾角, yaw: 指向, speed:地速(米/秒)

返回类型:

x: float, y: float, z: float, pitch: float, roll: float, yaw: float, speed: float

get_location()

根据节点实例获取当前节点的位置信息

返回:

x坐标, y坐标, z坐标, 当前帧时间戳

返回类型:

float, float, float, int

get_node_info()

获取该节点的基本信息,包括类型、编号、编队等

返回:

节点名称, 节点编号(队伍中编号), 节点编队归属(红/蓝), 节点类型(车/飞机、侦察类型/打击类型), 节点模型(具体型号), 颜色

返回类型:

str, int, str, str, str

get_sensor()

获取节点传感器信息接口 获取节点传感器载荷

返回:

{load_slot-插槽: swarmae_sensor-传感器载荷}, frame_timestamp:当前帧时间戳, code-返回状态码

get_sim_status()

获取节点仿真状态信息接口 获取当前节点的仿真状态信息,包括仿真中断/仿真正常/仿真未完成/完成待命/仿真失败等

返回:

sim_status-当前仿真状态, frame_timestamp-当前帧时间戳

get_vehicle_status()

获取车辆状态数据接口 获取当前车辆数据状态信息

返回:

throttle-油门, steer-转向, gear-档位, brake-手刹

返回类型:

float, float, int, float

get_velocity()

获取当前节点的速度信息

返回:

velocity_x-X分量速度 velocity_y-Y分量速度 velocity_z-Z分量速度 velocity-速度 acc_x-X分量加速度 acc_y-Y分量加速度 acc_z-Z分量加速度 acceleration-加速度 gs-地速 p-滚转角速度 q-俯仰角速度 r-航向角速度 frame_timestamp-当前帧时间戳

get_weapon()

获取节点武器信息接口 获取节点武器载荷

返回:

load_slot:插槽, swarmae_weapon:火力载荷, frame_timestamp:当前帧时间戳, code-返回状态码

gun_fire(num: Optional[int] = None)

火力打击-开火

Param:

num 打击次数(可选)

Type:

int

launch_kinetic(sim_type, count, switch, frame_timestamp)

动力学启动停止仿真接口 动力学启动停止仿真指令接口

警告

接口暂未提供

参数:
  • sim_type – 仿真类型

  • count – 数量

  • switch – 启动/停止

  • frame_timestamp – 当前帧时间戳

返回:

code-返回状态码, frame_timestamp: 返回帧时间戳

missile_fire(target_id: int)
receive_msg()

发送参数说明:

msg:载具发送的消息

send_msg(msg: bytes)

发送参数说明:

msg:载具发送的消息

set_fire_angle(yaw: float, pitch: float)

设置攻击角度

Param:

z轴, y轴

Type:

float, float

set_vehicle_brake(brake)

设置车辆控制刹车数据接口设置当前车辆刹车信息

参数:

brake (float) – 刹车力度 范围:[0.0, 1.0],默认为 0.0

返回:

frame_timestamp-响应帧时间戳, code-返回状态码

返回类型:

int, int

set_vehicle_gear(gear)

设置车辆控制档位数据接口 设置当前车辆档位信息

参数:

gear (int) – 档位

返回:

frame_timestamp-响应帧时间戳, code-返回状态码

返回类型:

int, int

set_vehicle_handle_brake(brake: bool)

设置当前车辆手刹信息。

参数:

brake (bool) – 手刹,默认值:False

返回:

响应帧时间戳, 返回状态码

返回类型:

int, int

set_vehicle_steer(steer)

设置当前车辆转向信息

参数:

steer (float) – 转向 范围:[-1.0, 1.0], 0.0 to [steer]

返回:

时间戳, 状态码

返回类型:

int, int

class swarmae.SwarmAESensor.SwarmAESensor(parameter, sensor_type)

基类:SwarmAEActor

mport 传感器实例类,继承SwarmAEActor类。提供获取传感器的相关信息接口

get_image_data()

获取可视化数据接口 获取普通摄像机采集的原始图形数据信息

返回:

image_data-图形数据流, swarmae_sensor_basic-传感器基础信息

返回类型:

array, SwarmAESensorBasic

get_rawdata()

获取原始数据接口 获取传感器原始数据信息

返回:

swarmae_sensor_basic-传感器基础信息, fov-以度为单位的水平视场, raw_data-原始数据的数组

返回类型:

SwarmAESensorBasic, float, bytes

get_semantic()

获取周围物体语义数据接口 获取周围物体语义信息

返回:

swarmae_sensor_basic-传感器基础信息(根据传感器类型不同,返回的具体字段数据不同),

x-物体所在位置X, y-物体所在位置Y, z-物体所在位置Z, size-大小, heading-朝向, bounding_box-包围盒, object_type-物体类型

get_sensor_angle()

获取传感器角度接口 获取该传感器当前的角度

返回:

angle-角度, frame_timestamp-当前帧时间戳

返回类型:

json-{“yaw”: rotation.yaw, “pitch”: rotation.pitch, “roll”: rotation.roll},int

get_sensor_energy()

获取传感器能源接口 获取传感器的能源

参数:
  • energy – 能源

  • frame_timestamp – 当前帧时间戳

返回:

current_energy-当前能源值, frame_timestamp-当前帧时间戳

返回类型:

int, int

get_sensor_status()

获取传感器状态接口 获取该传感器当前的状态信息

返回:

is_available-是否可用, is_working-工作中, is_sent-数据分发, frame_timestamp-当前帧时间戳

返回类型:

bool, bool, bool, int

set_sensor_angle(angle, frame_timestamp)

设置传感器角度接口 设置当前传感器的角度信息

参数:
  • angle – 角度

  • frame_timestamp – 当前帧时间戳

返回:

frame_timestamp-响应帧时间戳, code-返回状态码

返回类型:

int, int

class swarmae.SwarmAESensorBasic.SwarmAESensorBasic(sensor_type, frame, timestamp, transform, horizontal_angle, channels, width, height, frame_timestamp)

基类:object

传感器基础实例类。提供传感器的相关信息封装

参数:
  • sensor_type – 传感器类型

  • frame (int) – 测量发生时的时间

  • timestamp (float) – 自开始以来以秒为单位的测量模拟时间

  • transform (Transform) – 测量时传感器的世界坐标中的位置和姿态

  • horizontal_angle (float) – 当前帧中传感器的XY平面中的角度(弧度)

  • channels (int) – 传感器的通道数

  • width – 图像宽度(以像素为单位)

  • height – 图像高度(以像素为单位)

  • frame_timestamp (int) – 当前帧时间戳

class swarmae.SwarmAEUtils.SwarmAEUtils

基类:object

FAIL = 500
OVERTIME = 400
SUCCESS = 200
static get_frame_timestamp()
class swarmae.SwarmAEWeapon.SwarmAEWeapon(actor)

基类:SwarmAEActor

火力载荷实例类,继承SwarmAEActor类。提供获取和设置火力载荷的相关信息接口

get_weapon_ammo()

获取火力载荷弹药接口 获取火力载荷的弹药信息

返回:

is_available-是否可用, ammo_count-剩余弹药数, frame_timestamp-当前帧时间戳

返回类型:

bool, int, int

get_weapon_angle()

获取火力载荷角度接口 获取火力载荷的角度信息

返回:

angle-获取当前载具开火角度(yaw,pitch), frame_timestamp-当前帧时间戳

返回类型:

angle(int,int), int

get_weapon_config()

获取载荷配置信息接口 获取当前节点的载荷配置信息,包括打击载荷、传感器等对应载荷的类型、模型等信息

返回:

load_name-载荷名称, load_no-载荷编号, load_slot-接口所在插槽, load_type-载荷类型(打击载荷/传感器), ammo_count-弹药数,

load_model-载荷模型(具体型号), color-颜色, aggressivity-杀伤力, range-杀伤半径, energy-能源值

get_weapon_energy()

获取火力载荷能源接口 获取火力载荷的能源信息

返回:

energy-当前能源值, frame_timestamp-当前帧时间戳

返回类型:

int, int

get_weapon_fire()

获取火力载荷开火接口 获取火力载荷的开火信息

返回:

is_fire-是否开火, frame_timestamp-当前帧时间戳

返回类型:

bool, int

set_weapon_ammo(reset_ammo, frame_timestamp)

设置火力载荷弹药接口 设置载荷的上弹

参数:
  • reset_ammo (bool) – 上弹

  • frame_timestamp (int) – 当前帧时间戳

返回:

frame_timestamp-响应帧时间戳, code-返回状态码

返回类型:

int, int

set_weapon_angle(barrel_angle, barrel_altitude, frame_timestamp)

设置火力载荷角度接口 设置指定火力载荷的角度信息

参数:
  • barrel_angle (float) – 炮筒角度(Z轴)

  • barrel_altitude (float) – 炮筒高度角(Y轴)

  • frame_timestamp (int) – 当前帧时间戳

返回:

frame_timestamp-响应帧时间戳, code-返回状态码

返回类型:

int, int

set_weapon_status(ammo_number, frame_timestamp)

设置火力载荷状态接口 设置载荷的开火

参数:
  • ammo_number (int) – 发射子弹数量

  • frame_timestamp (int) – 当前帧时间戳

返回:

frame_timestamp-响应帧时间戳, code-返回状态码

返回类型:

int,int

class swarmae.SwarmAEWorld.SwarmAEWorld(world, targets=None)

基类:object

世界实例类,提供获取世界环境的相关信息接口

get_environment_objects()

获取所有环境信息

返回:

环境信息列表。环境信息物体的位置旋转信息(transform)、边界框(bounding_box)等信息

返回类型:

list

提供版本:

1.0.1

返回信息示例:

>>> 其中一条数据如下:
>>> result = {EnvironmentObject}
>>>   id = {int} 5148036365721985073
>>>   name = {str} 'SM_SpeedBump_0_SM_0'
>>>   transform = {Transform}
>>>      location = {Location}
>>>        x = {float} -1072.719970703125
>>>        y = {float} 439.79998779296875
>>>        z = {float} 486.446044921875
>>>      rotation = {Rotation}
>>>        pitch = {float} 0.0
>>>        roll = {float} 0.0
>>>        yaw = {float} 0.0
>>>   bounding_box = {BoundingBox}
>>>     extent = {Vector3D}
>>>       x = {float} 0.19999998807907104
>>>       y = {float} 30.000009536743164
>>>       z = {float} 0.010476627387106419
>>>     location = {Location}
>>>       x = {float} -1072.719970703125
>>>       y = {float} 439.79998779296875
>>>       z = {float} 486.446044921875
>>>     rotation = {Rotation}
>>>       pitch = {float} 0.0
>>>       roll = {float} 0.0
>>>       yaw = {float} 0.0
get_interference(node_id)

获取干扰数据信息接口 根据节点获取附近干扰区域信息

警告

接口暂未提供

参数:

node_id – 节点id

返回:

  • interference_type - 干扰类型,

  • interference_loc - 干扰源位置,

  • interference_range - 烦扰范围,

  • interference_str - 干扰强度,

  • interference_time - 干扰时间,

  • frame_timestamp - 当前帧时间戳

get_light()

获取光照信息接口 获取环境的光照信息

返回:

  • sun_altitude - 太阳高度角,

  • sun_azimuth - 太阳方位角,

  • frame_timestamp - 当前帧时间戳

返回类型:

float, float, int

get_map(map_filter)

获取地图信息接口 获取环境的基本地图信息

参数:

map_filter – 过滤条件(可选。高精、栅格等)

返回:

  • hd_map - 高精地图

  • grid_map - 栅格地图 (暂未提供,返回None)

  • map_name - 地图名称

  • frame_timestamp - 当前帧时间戳

get_targets()

获取敌人列表

返回:

敌人列表

返回信息示例:

>>> [
>>>  {"id": 敌人ID, "location": 敌人location, "health_point": 敌人healthponit}
>>> ]
get_weather(weather_filter)

获取环境的云水风等天气信息

参数:

weather_filter

过滤条件(可选。风雨雾风等), 例如,[“cloud”,

”precipitation”, “wind_intensity”, “fog_intensity”, “humidity”]

返回:

{cloud-云量, precipitation-降水量, wind_intensity-风强, fog_intensity-雾霾强度, humidity-湿度, frame_timestamp-当前帧时间戳}

返回类型:

dict

get_zone(node_id)

获取周围区域信息接口 根据节点ID获取附近区域,包括风场/林场/隔离带等

警告

接口暂未提供

参数:

node_id – 节点id

返回:

  • zone_type - 区域类型(风场/林场/隔离带),

  • zone_loc - 区域中心位置,

  • zone_size - 区域大小,

  • zone_shape - 区域形状,

  • points - 定点位置,

  • radius - 半径,

  • frame_timestamp - 当前帧时间戳