<commit_before># px4_control
ROS control interface for PX4 quadcopters. The main motivation of the existence for this REPO is to have a position controller that takes into consideration Position + Velocity + Acceleration from a Path Planner. This allows precise position control instead of PX4's own position controller that only takes into consideration either Position OR Velocity OR Acceleration commands.

This software has three different modes that one can choose from:

- Attitude mode: this mode sends thrust and attitude references based on a Xbox joystick.

- Local Position Control mode: this mode gets Position+Velocity+Acceleration references, calculates control commands and sends thrust + attitude to Px4. The controller is based on:
http://ieeexplore.ieee.org/abstract/document/5717652/

- Px4 Position Control mode: this mode gets position references and sends them to Px4's own position controller. 

The References for the previously mentioned Position Controllers can come from two different sources:

- Joystick: this software can already take in data from joysticks and integrate them to get smooth Position + Velocity + Acceleration references.

- ROS Topic: this software can also take incoming references from a Path Planner that publishes into the topic ``` /px4_control/PVA_Ref```

## Dependencies

- This software was developed for ROS Kinetic in Ubuntu 16.04. We haven't tested for other distributions. See installation procedure in http://wiki.ros.org/kinetic/Installation/Ubuntu.

- Eigen

```sudo apt-get install libeigen3-dev ```

- MAVROS

``` sudo apt-get install ros-kinetic-mavros ros-indigo-mavros-extras```

- ROS Joystick Drivers (we have only tested Wired XBox One, Wireless Xbox 360, and Wired Xbox 360 controllers):

```https://github.com/ros-drivers/joystick_drivers```


## Compiling

- Copy the present REPO into a catkin workspace, e.g.:

```
cd ~/catkin_ws/src
git clone <EMAIL>:marcelinomalmeidan/px4_control.git
```

- Compile the catkin workspace, e.g.:

```
cd ~/catkin_ws
catkin_make
```

## Testing

- We recommend test in simulation before testing with a real Quadcopter. Examples of PX4 simulation environments are Gazebo (https://dev.px4.io/en/simulation/gazebo.html) or Microsoft's Airsim (https://github.com/Microsoft/AirSim).

- In order to test the software from this repo, the following steps should be taken:
	- Run PX4 software
	- Run MAVROS (an example of .launch file is in ```/Extras```)
	- Run Joystick driver (an example of .launch file is in ```/Extras```)
	- Run px4_control (examples of .launch files can be found in ```/launch```)

**The following joystick buttons correspond to:**

* A: Land Mode (turn motors off)
* B: ROS Position Control Mode
	* Position references come from the topic ```/px4_control/PVA_Ref```
* X: Joystick Position Control Mode
	* Altitude can be changed using LB and RB. Horizontal translation can be changed using the Right Analog Directional. Yaw reference is changed when pushing LT and RT.
* Y: Joystick Attitude Mode.
	* Roll and Pitch are commanded through the Joystick's Right Analog Directional. Thrust is commanded through the Left Analog Directional. Yaw reference is changed when pushing LT and RT.


## Tuning Position Controller PID

All the controller PID parameters can be set in the .launch file. However, it might be tedious to stop the controller every time that one wants to change/tune the PID gains. In order to avoid stopping the controller for every parameter change, the following services are implemented:

- ```/px4_control_node/updateQuadParam```: Used to update flight parameters in the following order: mass, gravity and thrustRatio. This can be called in line command as below:

	- ```rosservice call /px4_control_node/updateQuadParam '[0.5, 9.81, 2.4]'```

- ```/px4_control_node/updatePosControlParam```: Used to update PID parameters if the following order: kpx, kpy, kpz, kvx, kvy, kvz, kix, kiy, kiz, maxInteg_x maxInteg_y maxInteg_z. An example of command line to call this service is shown below:

	- ```rosservice call /px4_control_node/updatePosControlParam '[10, 10, 10, 5, 5, 7.5, 0, 0, 0, 0, 0, 0]'```

An alternative to call these parameters is to use the Matlab script in ```/Extras/SetParametersGazebo.m```. However, this requires Matlab with the Robotics Toolbox installed. <commit_msg>update in readme<commit_after># px4_control
ROS control interface for PX4 quadcopters. The main motivation of the existence for this REPO is to have a position controller that takes into consideration Position + Velocity + Acceleration from a Path Planner. This allows precise position control instead of PX4's own position controller that only takes into consideration either Position OR Velocity OR Acceleration commands.

This software has three different modes that one can choose from:

- Attitude mode: this mode sends thrust and attitude references based on a Xbox joystick.

- Local Position Control mode: this mode gets Position+Velocity+Acceleration references, calculates control commands and sends thrust + attitude to Px4. The controller is based on:
http://ieeexplore.ieee.org/abstract/document/5717652/

- Px4 Position Control mode: this mode gets position references and sends them to Px4's own position controller. 

The References for the previously mentioned Position Controllers can come from two different sources:

- Joystick: this software can already take in data from joysticks and integrate them to get smooth Position + Velocity + Acceleration references.

- ROS Topic: this software can also take incoming references from a Path Planner that publishes into the topic ``` /px4_control/PVA_Ref```

## Dependencies

- This software was developed for ROS Kinetic in Ubuntu 16.04. We haven't tested for other distributions. See installation procedure in http://wiki.ros.org/kinetic/Installation/Ubuntu.

- Eigen

```sudo apt-get install libeigen3-dev ```

- MAVROS

``` sudo apt-get install ros-kinetic-mavros ros-indigo-mavros-extras```

- ROS Joystick Drivers (we have only tested Wired XBox One, Wireless Xbox 360, and Wired Xbox 360 controllers):

```https://github.com/ros-drivers/joystick_drivers```


## Compiling

- Copy the present REPO into a catkin workspace, e.g.:

```
cd ~/catkin_ws/src
git clone <EMAIL>:marcelinomalmeidan/px4_control.git
```

- Compile the catkin workspace, e.g.:

```
cd ~/catkin_ws
catkin_make
```

## Testing

- We recommend test in simulation before testing with a real Quadcopter. Examples of PX4 simulation environments are Gazebo (https://dev.px4.io/en/simulation/gazebo.html) or Microsoft's Airsim (https://github.com/Microsoft/AirSim).

- In order to test the software from this repo, the following steps should be taken:
	- Run PX4 software
	- Run MAVROS (an example of .launch file is in ```/Extras```)
	- Run Joystick driver (an example of .launch file is in ```/Extras```)
	- Run px4_control (examples of .launch files can be found in ```/launch```)

**The following joystick buttons correspond to:**

![Xbox Controller](http://compass.xboxlive.com/assets/c7/a1/c7a12fbe-af04-4a90-92f2-18338219c2aa.png?n=one-controller-front-l.png "Xbox Controller")

* A: Land Mode (turn motors off)
* B: ROS Position Control Mode
	* Position references come from the topic ```/px4_control/PVA_Ref```
* X: Joystick Position Control Mode
	* Altitude can be changed using LB and RB. Horizontal translation can be changed using the Right Stick. Yaw reference is changed when pushing LT and RT.
* Y: Joystick Attitude Mode.
	* Roll and Pitch are commanded through the Joystick's Right Stick. Thrust is commanded through the Left Stick. Yaw reference is changed when pushing LT and RT.
* Directional Pad (Left): Select Local Position Control mode. 
* Directional Pad (Right): Select Px4 Position Control mode. 


## Tuning Position Controller PID

All the controller PID parameters can be set in the .launch file. However, it might be tedious to stop the controller every time that one wants to change/tune the PID gains. In order to avoid stopping the controller for every parameter change, the following services are implemented:

- ```/px4_control_node/updateQuadParam```: Used to update flight parameters in the following order: mass, gravity and thrustRatio. This can be called in line command as below:

	- ```rosservice call /px4_control_node/updateQuadParam '[0.5, 9.81, 2.4]'```

- ```/px4_control_node/updatePosControlParam```: Used to update PID parameters if the following order: kpx, kpy, kpz, kvx, kvy, kvz, kix, kiy, kiz, maxInteg_x maxInteg_y maxInteg_z. An example of command line to call this service is shown below:

	- ```rosservice call /px4_control_node/updatePosControlParam '[10, 10, 10, 5, 5, 7.5, 0, 0, 0, 0, 0, 0]'```

An alternative to call these parameters is to use the Matlab script in ```/Extras/SetParametersGazebo.m```. However, this requires Matlab with the Robotics Toolbox installed. 
{'fraction_non_alphanumeric': 0.08010335917312661, 'fraction_numerical': 0.015616222896303785, 'mean_word_length': 4.56375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1706859', 'n_tokens_mistral': 2713, 'n_tokens_neox': 2486, 'n_words': 1149}