AutonomyLab/ardrone_autonomy — pull request #96 by mikeclement (2014-03-21 00:12:36+00:00)
Title: Added custom network port specification

This follows up on: https://github.com/AutonomyLab/ardrone_autonomy/issues/56#issuecomment-36702633

Note: this patch does NOT affect the default behavior of ardrone_driver; optional command-line arguments must be supplied to introduce the described behavior.

I've incorporated a solution based on manually specifying custom ports for each instance of the ardrone_driver node and using iptables (root privileges required) to remap UDP packets en route. The options follow from the port names, e.g., -navdata-port, -video-port, and -at-port. As far as I can tell, these are the only three that need to be customized, but the other port numbers are also made into options for completeness.

To test: first, join the quads into a common network. Supposing two quads, q1 at 192.168.0.101 and q2 at 192.168.0.102, we choose to remap ports as follows:

q1: 5554 (quad) <-> 1554 (ardrone_driver), 5555 <-> 1555, 5556 <-> 1556
q2: 5554 (quad) <-> 2554 (ardrone_driver), 5555 <-> 2555, 5556 <-> 2556

The corresponding iptables commands would be:

q1:
```bash
sudo iptables -t nat -A OUTPUT -p udp -d 192.168.0.101 --dport 1554 -j DNAT --to :5554
sudo iptables -t nat -A PREROUTING -p udp -s 192.168.0.101 --dport 5554 -j DNAT --to :1554
sudo iptables -t nat -A OUTPUT -p udp -d 192.168.0.101 --dport 1555 -j DNAT --to :5555
sudo iptables -t nat -A PREROUTING -p udp -s 192.168.0.101 --dport 5555 -j DNAT --to :1555
sudo iptables -t nat -A OUTPUT -p udp -d 192.168.0.101 --dport 1556 -j DNAT --to :5556
sudo iptables -t nat -A PREROUTING -p udp -s 192.168.0.101 --dport 5556 -j DNAT --to :1556
```
q2:
```bash
sudo iptables -t nat -A OUTPUT -p udp -d 192.168.0.102 --dport 2554 -j DNAT --to :5554
sudo iptables -t nat -A PREROUTING -p udp -s 192.168.0.102 --dport 5554 -j DNAT --to :2554
sudo iptables -t nat -A OUTPUT -p udp -d 192.168.0.102 --dport 2555 -j DNAT --to :5555
sudo iptables -t nat -A PREROUTING -p udp -s 192.168.0.102 --dport 5555 -j DNAT --to :2555
sudo iptables -t nat -A OUTPUT -p udp -d 192.168.0.102 --dport 2556 -j DNAT --to :5556
sudo iptables -t nat -A PREROUTING -p udp -s 192.168.0.102 --dport 5556 -j DNAT --to :2556
```

Now, when running instances of ardrone_driver, add the following args strings:

q1:
```bash
-ip 192.168.0.101 -navdata-port 1554 -video-port 1555 -at-port 1556
```
q2:
```bash
-ip 192.168.0.102 -navdata-port 2554 -video-port 2555 -at-port 2556
```

More information as well as tools for automating wireless reconfiguration and port remapping are available here:
http://hacked10bits.blogspot.com/2014/02/multiple-ardrones-from-single-computer.html