Skip to content

Commit

Permalink
Merge pull request #36 from h2r/release/v2.3
Browse files Browse the repository at this point in the history
PR for merging release/v2.3 into master
  • Loading branch information
nkumar15-brown-university authored Aug 16, 2019
2 parents 1b62d93 + 92e3a1a commit 57126cb
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 3 deletions.
Binary file removed PiMount V2.stl
Binary file not shown.
Binary file added PiMount_V3.stl
Binary file not shown.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,38 @@ For Stefanie Tellex's class

- See web interface for a list of drone input controls.

## How to Connect to Home Network

1. (Skip step if done before)
On drone, run the following:
- ```
cd /etc/wpa_supplicant
sudo ./generate_wpa_supplicant_conf.sh
```
or alternatively
```
roscd pidrone_pkg/
cd networking
sudo ./generate_wpa_supplicant_conf.sh
sudo mv wpa_supplicant.conf /etc/wpa_supplicant
```
When prompted, enter credentials for home network.
2. On drone, run the following:
- ```
roscd pidrone_pkg/
python networking/connect_to_user_wifi.py
```
or alternatively
```
cd /etc/wpa_supplicant
./connect_to_user_wifi.sh
```
- the ssh session to the drone will terminate shortly after. The wifi connection to the drone will disconnect.
3. On base station:
- connect to home network (instead of drone network)
- open a terminal or command prompt and run `ssh duckiesky@<hostname>`, where `<hostname>` is the hostname of the drone (found in file `/etc/hostname`). The default is `duckiesky-drone`.
- A password prompt will appear. After entering the password, the ssh connection to the drone will be complete.
## Warnings
- Starting with release v2.2-kinetic, all releases work on ROS Kinetic (unless specified otherwise). Older releases do not - they only work up to ROS Indigo. Furthermore, releases v2.2-kinetic and higher do not have backward compatibility with older versions of ROS.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2-kinetic
2.3-kinetic
2 changes: 1 addition & 1 deletion connect_to_rlab.py → networking/connect_to_user_wifi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
os.system("sudo ifdown wlan0")
# Starting wpa_supplicant
os.system("sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf")
os.system("sudo ifup wlan0=rlab_wifi")
os.system("sudo ifup wlan0=user_wifi")
26 changes: 26 additions & 0 deletions networking/connect_to_user_wifi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Purpose: Stops the device from running as a DHCP
# server, then puts it on the network
# specified in WPA_SUPP_CONF_FILE.
# NOTE: Re-tooled from connect_to_user_wifi.py
# in h2r/pidrone_pkg github repo.
# Author: Nishant Kumar
# Contact: [email protected]

WPA_SUPP_CONF_FILE="/etc/wpa_supplicant/wpa_supplicant.conf"
WIFI="user_wifi"

if [[ ! -r "${WPA_SUPP_CONF_FILE}" ]]; then
echo "Missing required conf file ${WPA_SUPP_CONF_FILE}. Please create it and try again."
exit 1
fi

# Stopping Services
sudo systemctl stop hostapd
sudo systemctl stop isc-dhcp-server.service
sudo ifdown wlan0

# Starting wpa_supplicant
sudo wpa_supplicant -B -i wlan0 -c "${WPA_SUPP_CONF_FILE}"
sudo ifup wlan0="${WIFI}"
61 changes: 61 additions & 0 deletions networking/generate_wpa_supplicant_conf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

# Purpose: Generates a new wpa_supplicant.conf file by
# inserting user-provided network credentials
# (with hashed password for security) into a
# template wpa_supplicant conf file.
# Author: Nishant Kumar
# Contact: [email protected]

WPA_CONF_TEMPLATE="wpa_supplicant.conf.template"
OUTPUT_FILE="wpa_supplicant.conf"
BACKUP_FILE="${OUTPUT_FILE}"".bak"
TEMP_FILE_FOR_GENERATED_NETWORK="/tmp/generated_network.XXXX"

function print_wpa_passphrase_error() {
if [[ -n "${temp_generated}" ]]; then
echo "${temp_generated}" | sed '/#.*$/d'
fi
}

function cleanup() {
echo "Cleaning up..."
shred -n 50 -z -u "${TEMP_FILE_FOR_GENERATED_NETWORK}" > /dev/null 2>&1
echo Done
}

trap "ec=\$?; cleanup; exit \$ec" EXIT INT
trap "ec=\$?; print_wpa_passphrase_error; exit \$ec" ERR

read -ep "Enter network's ssid: " ssid
read -esp "Enter network's password: " pass1
echo
read -esp "Verify network's password: " pass2
echo

if [[ "$pass1" != "$pass2" ]];
then
echo "Password verification failed. Please try again."
exit 1
fi

if [[ -f "${OUTPUT_FILE}" ]];
then
cp "${OUTPUT_FILE}" "${BACKUP_FILE}"
echo Backed up current "${OUTPUT_FILE}" to "${BACKUP_FILE}"
fi

temp_generated="$(echo "${pass1}" | wpa_passphrase "${ssid}")"
echo "${temp_generated}" | sed '/#.*$/d' > "${TEMP_FILE_FOR_GENERATED_NETWORK}"
echo "Generated new network configuration"

# If reached this far, ERR trap did not trigger due to wpa_passphrase error.
# So if ERR trap triggers after this point, it should not print temp_generated,
# since wpa_passphrase is not to blame (i.e. temp_generated does not contain
# an error message). Therefore, setting temp_generated to blank so that
# print_wpa_passphrase_error func does not print it.
temp_generated=


sed -e "/<network>/r ${TEMP_FILE_FOR_GENERATED_NETWORK}" -e '//d' < "${WPA_CONF_TEMPLATE}" > "${OUTPUT_FILE}"
echo "Inserted new network configuration into template ${WPA_CONF_TEMPLATE}, then overwrote ${OUTPUT_FILE}"
5 changes: 5 additions & 0 deletions networking/wpa_supplicant.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
country=us
update_config=1
ctrl_interface=/var/run/wpa_supplicant

<network>
2 changes: 1 addition & 1 deletion scripts/pid_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def main(ControllerClass):

# Safety check to ensure drone does not fly too high
if (pid_controller.current_state.pose_with_covariance.pose.position.z >
0.5):
0.7):
fly_command = cmds.disarm_cmd
print("\n disarming because drone is too high \n")
break
Expand Down

0 comments on commit 57126cb

Please sign in to comment.