Setup a Controller¶
This tutorial will show you how to find your controller layout and add it as a configuration.
- Connect the controller to your computer
Note
You may need to download additional drivers. (i.e drivers for ps4 controller )
- Add new controller to conf file.
# Add to ../crazyflie_charles/ros_ws/src/formation_manager/conf/swarm_conf.yaml
controller_name:
axes: # Axes start at 0
x: _
y: _
z: _
yaw: _
buttons:
'0': _
'1': _
'2': _
buttons_axes:
'-0': DL
'0' : DR
'1' : DU
'-1': DD
max_goal:
x: 0.20
y: 0.20
z: 0.10
yaw: 0.20
Read controller input
$ rosrun joy joy_node
Map joystick controls
3.1. In a new terminal, print information
$ rostopic echo /joy
3.2 Add buttons to conf file
Find number of each button.
controller_name: ... buttons: '0': _ '1': _ '2': X ...
3.3 Add axes to conf file
You have four controls to map: x position, y position, z position and yaw.
Let’s say you want to map the horizontal right stick to yaw control and get this result when moving the stick to the left.
Based on the picture, we can find that the horizontal right stick axis number is 2. Also, since moving it to the left gives a positive result, the axis number will be negative:
controller_name: ... axes: x: y: z: yaw: -2 ...
Repeat this for all controls you wish to map.
Add controller to API:
# .../crazyflie_charles/ros_ws/src/swarm_manager/scripts/swarm_api/api.py class SwarmAPI(object): ... def start_joystick(self, joy_type=""): """Initialize joystick node Possible types are: - ds4 - ADD NEW CONTROLLER ... """ ...
Try new controller with api by using
SwarmAPI.start_joystick("new_controller")