forked from hchengwang/Software-duckietown
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python | ||
# license removed for brevity | ||
import rospy | ||
import sys | ||
|
||
from sensor_msgs.msg import Joy | ||
|
||
from __builtin__ import True | ||
|
||
|
||
def keyCatcher(host): | ||
pub = rospy.Publisher('/'+host+'/joy', Joy, queue_size=1) | ||
rospy.init_node('joy-cli', anonymous=True) | ||
|
||
while not rospy.is_shutdown(): | ||
direction = raw_input('Enter direction(a,w,s,d)--> ') | ||
if direction == 'w': | ||
axes = [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] | ||
elif direction == 's': | ||
axes = [0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] | ||
elif direction == 'd': | ||
axes = [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0] | ||
elif direction == 'a': | ||
axes = [0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0] | ||
else: | ||
axes = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] | ||
|
||
msg = Joy(header=None, axes=axes, buttons=None) | ||
pub.publish(msg) | ||
rospy.sleep(0.5) | ||
|
||
axes = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] | ||
msg = Joy(header=None, axes=axes, buttons=None) | ||
pub.publish(msg) | ||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) < 2: | ||
raise Exception("No hostname specified!") | ||
else: | ||
hostname = sys.argv[1] | ||
|
||
try: | ||
keyCatcher(host = hostname) | ||
except rospy.ROSInterruptException: | ||
pass | ||
|