Skip to content

Commit

Permalink
added virtual_joystick
Browse files Browse the repository at this point in the history
  • Loading branch information
afdaniele committed Apr 22, 2020
1 parent 9e4f7de commit f1b0591
Show file tree
Hide file tree
Showing 12 changed files with 406 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/virtual_joystick/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 2.8.3)
project(virtual_joystick)

find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
duckietown_msgs # Every duckietown packages should use this.
)


catkin_python_setup()


catkin_package()

include_directories(
${catkin_INCLUDE_DIRS}
)
Binary file added packages/virtual_joystick/images/d-e-stop-big.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/virtual_joystick/images/d-e-stop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/virtual_joystick/images/d-pad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/virtual_joystick/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions packages/virtual_joystick/launch/virtual_joystick_cli.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<launch>
<arg name="veh" doc="name of the vehicle"/>
<arg name="pkg_name" value="virtual_joystick"/>
<arg name="node_name" default="virtual_joystick"/>

<group ns="$(arg veh)">
<remap from="$(arg node_name)/joy" to="joy" />
<node pkg="$(arg pkg_name)" type="$(arg node_name)_cli.py" name="$(arg node_name)" output="screen" />
</group>
</launch>
13 changes: 13 additions & 0 deletions packages/virtual_joystick/launch/virtual_joystick_gui.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<launch>
<arg name="veh" doc="name of the vehicle"/>
<arg name="pkg_name" value="virtual_joystick"/>
<arg name="node_name" default="virtual_joystick"/>

<group ns="$(arg veh)">
<remap from="$(arg node_name)/joy" to="joy" />
<remap from="$(arg node_name)/intersection_go" to="coordinator_node/intersection_go" />
<remap from="$(arg node_name)/emergency_stop" to="wheels_driver_node/emergency_stop" />
<node pkg="$(arg pkg_name)" type="$(arg node_name)_gui.py" name="$(arg node_name)" output="screen" args="$(arg veh)" />
</group>
</launch>
24 changes: 24 additions & 0 deletions packages/virtual_joystick/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<package>
<name>virtual_joystick</name>
<version>1.0.0</version>
<description>
A package for launching the virtual joystick in gui or cli
</description>

<author email="[email protected]">Mack</author>
<maintainer email="[email protected]">Mack</maintainer>

<license>GPLv3</license>

<buildtool_depend>catkin</buildtool_depend>
<build_depend>duckietown_msgs</build_depend>
<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>


<run_depend>duckietown_msgs</run_depend>
<run_depend>roscpp</run_depend>
<run_depend>rospy</run_depend>

</package>
61 changes: 61 additions & 0 deletions packages/virtual_joystick/scripts/virtual_joystick_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python2
import rospy

from sensor_msgs.msg import Joy


# Button List index of joy.buttons array:
# 0: A
# 1: B
# 2: X
# 3: Y
# 4: Left Back
# 5: Right Back
# 6: Back
# 7: Start
# 8: Logitek
# 9: Left joystick
# 10: Right joystick


# TODO: This should be a class

def keyCatcher():
rospy.init_node('joy-cli')
pub = rospy.Publisher('~joy', Joy, queue_size=1)

while not rospy.is_shutdown():
axes = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
buttons = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
direction = raw_input(
'Enter direction [a,w,s,d] to move; '
'[l] to start lane following; '
'[q] to stop lane following; '
'[e] to toggle emergency stop; '
'then press enter to execute --> ')
if direction == 'w':
axes[1] = 1.0
elif direction == 's':
axes[1] = -1.0
elif direction == 'd':
axes[3] = -1.0
elif direction == 'a':
axes[3] = 1.0
elif direction == 'l':
buttons[7] = 1
elif direction == 'q':
buttons[6] = 1
elif direction == 'e':
buttons[3] = 1
# publish joy message
msg = Joy(header=None, axes=axes, buttons=buttons)
pub.publish(msg)
rospy.sleep(0.5)


if __name__ == '__main__':
try:
keyCatcher()
except rospy.ROSInterruptException:
pass

Loading

0 comments on commit f1b0591

Please sign in to comment.