Skip to content

Commit

Permalink
Merge pull request esa-prl#8 from esa-prl/dev
Browse files Browse the repository at this point in the history
* Fixed a bug that caused the motors to only stop delayed.
* New shell scripts make starting and configuring of docker containers easier.
* Minor refactoring
* Minor web-GUI improvements
* Add enable disable funcationality to motors.
* Add "motors" button to enable and disable motors.
* Changed the button allocation on the gamepad:
  * Y - Crabbing
  * X - Spot turn
  * A - Ackerman
  * Start - Enable Motors
  • Loading branch information
Miro Voellmy authored Aug 27, 2020
2 parents 21a01a2 + c36beac commit 8f92f63
Show file tree
Hide file tree
Showing 16 changed files with 351 additions and 299 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ find_package(catkin REQUIRED COMPONENTS
## Generate messages in the 'msg' folder
add_message_files(
FILES
Joystick.msg
Commands.msg
RoverCommand.msg
MotorCommands.msg
Screen.msg
)
## Generate services in the 'srv' folder
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# Basic tools
RUN apt-get update && \
apt-get install vim git tmux wget curl python-pip -y
apt-get install vim nano git tmux wget curl python-pip net-tools iputils-ping -y

# Install additional ros packages
RUN apt-get update && apt-get install ros-melodic-rosbridge-server ros-melodic-joy -y
Expand Down
6 changes: 3 additions & 3 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
if [ $1 == "config" ]
if [[ $1 == "config" ]]
then
cd /root/exomy_ws/src/exomy/scripts
bash
elif [ $1 == "autostart" ]
elif [[ $1 == "autostart" ]]
then
source /opt/ros/melodic/setup.bash
cd /root/exomy_ws
Expand All @@ -14,7 +14,7 @@ then
roslaunch exomy exomy.launch

bash
elif [ $1 == "ros" ]
elif [[ $1 == "devel" ]]
then
cd /root/exomy_ws
source /opt/ros/melodic/setup.bash
Expand Down
75 changes: 75 additions & 0 deletions docker/run_exomy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash
# run_exomy- A script to run containers for dedicated functions of exomy

help_text="Usage: "$0" [MODE] [OPTIONS]
A script to run ExoMy in different configurations
Options:
-a, --autostart Toggles autostart mode on or off
-c, --config Runs the motor configuration of ExoMy
-d, --devel Runs the development mode to change some code of ExoMy
-h, --help Shows this text
"

### Main
# Initialize parameters
container_name="exomy"
image_name="exomy"

# Process parameters
if [ "$1" != "" ]; then
case $1 in
-a | --autostart)
container_name="${container_name}_autostart"
start_command="autostart"
options="--restart always"

;;
-s | --stop_autostart)
docker container stop "${container_name}_autostart"
exit
;;
-c | --config)
container_name="${container_name}_config"
start_command="config"
options="--rm"
;;
-d | --devel)
container_name="${container_name}_devel"
start_command="devel"
options="--restart always"
;;
-h | --help ) echo "$help_text"
exit
;;
* ) echo "ERROR: Not a valid mode!"
echo "$help_text"
exit 1
esac
else
echo "ERROR: You need to specify a mode!"
echo "$help_text"
exit
fi

# Build docker image from Dockerfile in directory
directory=$( dirname "$0" )
docker build -t $image_name $directory

# Stop any of the 3 containers if running
RUNNING_CONTAINERS=$( docker container ls -a -q --filter ancestor=exomy )
if [ -n "$RUNNING_CONTAINERS" ]; then
docker rm -f "$RUNNING_CONTAINERS"
fi

# Run docker container
docker run \
-it \
-v ~/ExoMy_Software:/root/exomy_ws/src/exomy \
-p 8000:8000 \
-p 8080:8080 \
-p 9090:9090 \
--privileged \
${options} \
--name "${container_name}" \
"${image_name}" \
"${start_command}"
68 changes: 29 additions & 39 deletions gui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
url: 'ws://' + host_url + ':9090'
});

// Initialize Axes and Buttons arrays
var axes = [0, 0, 0, 0, 0, 0];
var buttons = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];

ros.on('connection', function () {
document.getElementById("status").innerHTML = "Connected";
});
Expand Down Expand Up @@ -46,33 +50,33 @@
var max_distance = 75;
var x = -Math.cos(nipple.angle.radian) * nipple.distance / max_distance;
var y = Math.sin(nipple.angle.radian) * nipple.distance / max_distance;
axes = [x, y]
axes = [x, y, 0, 0, 0, 0]

// nipplejs is triggering events when joystick moves each pixel
// we need delay between consecutive messege publications to
// prevent system from being flooded by messages
// events triggered earlier than 50ms after last publication will be dropped

if (publishImmidiately) {
publishImmidiately = false;
joy_event()
window.clearInterval(watchdog_handle)
watchdog_handle=window.setInterval(joy_event, 50)

setTimeout(function () {
publishImmidiately = true;
}, 50);
}
publishImmidiately = false;
joy_event()
window.clearInterval(watchdog_handle)
watchdog_handle = window.setInterval(joy_event, 50)

setTimeout(function () {
publishImmidiately = true;
}, 50);
}
//joy_event()
//window.clearInterval()
//window.setInterval(joy_event, 500)
});

self.manager.on('end', function () {
window.clearInterval(watchdog_handle)
axes = [0, 0]
axes = [0, 0, 0, 0, 0, 0]
joy_event()
console.log('End function called')
console.log('End function called')
});
}
window.onload = function () {
Expand All @@ -99,30 +103,16 @@
console.log(buttons)
}

buttonY_clicked = function () {
axes = [0, 0]
buttons = [0, 0, 0, 1];
joy_event();
}
buttonX_clicked = function () {
axes = [0, 0]
buttons = [1, 0, 0, 0];
joy_event();
}
buttonB_clicked = function () {
axes = [0, 0]
buttons = [0, 0, 1, 0];
button_clicked = function (button_index) {
// The desired button index can be found by listening to the /joy ros message
// or by checking in the wiki for the gamepad mapping.
// Set axes to 0 to prevent driving during mode change.
axes = [0, 0, 0, 0, 0, 0];
buttons[button_index] = 1;
joy_event();
// After the command is sent set the index back to 0
buttons[button_index] = 0;
}
buttonA_clicked = function () {
axes = [0, 0]
buttons = [0, 1, 0, 0];
joy_event();
}

var axes = [0, 0];
var buttons = [0, 0, 0, 0];


</script>
<link rel="stylesheet" type="text/css" href="style.css">
Expand All @@ -133,8 +123,7 @@
<main>
<div class="wrapper">
<div class="left" id="left">
<div class="joy_container" id="joy_container">
</div>
<div class="joy_container" id="joy_container"></div>
</div>

<div class="middle" id="middle">
Expand All @@ -144,9 +133,10 @@
</div>
<div class="right" id="right">
<div class="button_container">
<button class="button buttonY" onclick="buttonY_clicked()">ACKERMANN</button>
<button class="button buttonB" onclick="buttonB_clicked()">POINT_TURN</button>
<button class="button buttonA" onclick="buttonA_clicked()">CRABBING</button>
<button class="button buttonY" onclick="button_clicked(3)">CRABBING</button>
<button class="button buttonX" onclick="button_clicked(0)">SPOT TURN</button>
<button class="button buttonA" onclick="button_clicked(1)">ACKERMANN</button>
<button class="button buttonStart" onclick="button_clicked(9)">MOTORS</button>
</div>
</div>
</div>
Expand Down
23 changes: 17 additions & 6 deletions gui/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,36 @@ body {
color: white;
text-decoration: none;
display: inline-block;
margin: 0 auto;
margin: 10px auto;
cursor: pointer;
width: 90%;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
font-size: 18px;
font-weight: bold;
border-radius: 8px;
}

.buttonY{
background-color: orange;
grid-row: 1;
}
.buttonB{
background-color: red;
.buttonX{
background-color: blue;
grid-row: 2;
}
.buttonA{
background-color: green;
grid-row: 3;
}

.buttonStart{
background-color: red;
grid-row: 4;
width: 50%;
font-size: 12px;

}

.button_container {
position: absolute;
display: grid;
Expand All @@ -51,9 +62,9 @@ body {
}
.image_container {
position: absolute;
top: 25%;
height: 100%;
width: 100%;
top: 20%;
height: 80%;
width: 80%;
}
.joy_container {
height: 100%;
Expand Down
2 changes: 1 addition & 1 deletion launch/exomy.launch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<launch>
<node name="robot" pkg="exomy" type="robot_node.py" respawn="true" output="screen"/>
<node name="motors" pkg="exomy" type="motor_node.py" respawn="true" output="screen" />
<node name="joystick" pkg="exomy" type="joystick_node.py" respawn="true" output="screen" />
<node name="joystick" pkg="exomy" type="joystick_parser_node.py" respawn="true" output="screen" />

<node respawn="true" pkg="joy" type="joy_node" name="joy_node">
<param name="coalesce_interval" value="0.05"/>
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions msg/Joystick.msg → msg/RoverCommand.msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bool connected
bool motors_enabled
int64 locomotion_mode
int64 vel
int64 steering
2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<package format="2">
<name>exomy</name>
<version>1.0.0</version>
<version>1.0.1</version>
<description>The ExoMy ROS package</description>

<maintainer email="[email protected]">Maximilian Ehrhardt</maintainer>
Expand Down
70 changes: 0 additions & 70 deletions src/joystick_node.py

This file was deleted.

Loading

0 comments on commit 8f92f63

Please sign in to comment.