Python API¶
start_joystick |
|
link_joy_button |
|
take_off |
|
stop |
|
emergency |
|
land |
|
set_mode |
|
set_formation |
|
next_formation |
|
prev_formation |
|
inc_scale |
|
dec_scale |
|
toggle_ctrl_mode |
|
go_to |
|
get_positions |
|
rotate_formation |
Python API to control the swarm.
This module maked it possible to easily send command to the swarm through a Python script.
Example¶
# Formation exemple
swarm = SwarmAPI()
# Link joystick buttons to commands
swarm.start_joystick("ds4")
swarm.link_joy_button("S", swarm.take_off)
swarm.link_joy_button("X", swarm.land)
swarm.link_joy_button("O", swarm.emergency)
swarm.link_joy_button("T", swarm.toggle_ctrl_mode)
# Start swarm
swarm.set_mode("formation")
swarm.set_formation("v")
swarm.take_off()
rospy.sleep(10)
# Change formation
swarm.set_formation("pyramid")
SwarmAPI
class¶
-
class
swarm_api.api.
SwarmAPI
[source]¶ Python API class
-
start_joystick
(joy_type, joy_dev='js0')[source]¶ Initialize joystick node. See here for a tutorial on how to add new joystick types.
Possible types:
- ds4
Parameters: - joy_type (
str
) – Controller type. - joy_dev (
str
, Optional) – Specify joystick port. Defaults to js0
-
set_joy_control
(to_control)[source]¶ To enable/disable control of formation position with joystick axes.
Parameters: to_control (bool) – If True, formation will be moved by joystick axes
Link a button to a function call
Parameters: - button_name (
str
) – Name of button, as written injoy_conf.yaml
. - func (
Callable
) – Function to call - args (optional) – Function args. Defaults to None. Can be a single arg or a list of args
- kwargs (
dict
, optional) – Function kwargs. Defaults to None.
Raises: KeyError
– Invalid button nameExample:
swarm.start_joystick("ds4") swarm.link_joy_button("S", swarm.take_off) swarm.link_joy_button("X", swarm.land)
- button_name (
-
take_off
()[source]¶ Take off all landed CFs.
Modify
take_off_height
inswarm_conf.yaml
to change take off heightNote
Will only take off landed CFs
-
set_mode
(new_mode)[source]¶ Set
SwarmController
control mode.- Possible modes are:
- Automatic: CF will plot trajectory to new goals. Send
go_to commands
from python script - Formation: Swarm moves in formation. Formation position can be moved /w joystick.
- Automatic: CF will plot trajectory to new goals. Send
- Not implemented:
- Pilot: Like CF client. No formation
- Assisted: Control change of position /w joystick. No formation.
Note
Modes are not case sensitive
Parameters: new_mode ( str
) – New control mode
-
set_formation
(formation_name)[source]¶ Set swarn formation
Parameters: formation_name ( str
) – New formation name
-
toggle_ctrl_mode
()[source]¶ Toggle control mode between absolute and relative.
In absolute: x, y, z are world axis
In relative: x, y, z depends on swarm orientation
-
go_to
(goals)[source]¶ Move formation and/or cf to a position using the trajectory planner.
Dict format:
"goal_name": [x, y, z, yaw]
where"goal_name"
is either"formation"
or"cf_x"
X, Y, Z in meters, Yaw in rad.
- Example::
# To move formation to [2, 2, 0.5, 1.57] swarm.go_to({‘formation’: [2, 2, 0.5, 1.57]})
# To move cf_0 to [0, 0, 0.5] and cf_1 to [1, 1, 1] goals = {} goals[“cf_0”] = [0, 0, 0.5, 0] goals[“cf_1”] = [1, 1, 1, 0] swarm.go_to(goals)
Parameters: goals ( dict
) – New goals
-