Skip to content

Commit

Permalink
Merge pull request RobotLocomotion#8745 from soonho-tri/fix-typo-in-a…
Browse files Browse the repository at this point in the history
…utomotive

Fix typo in automotive/steering_command_driver.py
  • Loading branch information
soonho-tri authored May 8, 2018
2 parents c24786a + 13d971b commit 705e72b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
12 changes: 12 additions & 0 deletions automotive/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ load(
"drake_cc_library",
"drake_cc_package_library",
)
load(
"@drake//tools/skylark:drake_py.bzl",
"drake_py_unittest",
)
load(
"@drake//tools/skylark:drake_java.bzl",
"drake_java_binary",
Expand Down Expand Up @@ -796,6 +800,14 @@ drake_cc_googletest(
],
)

drake_py_unittest(
name = "steering_command_driver_test",
deps = [
":steering_command_driver",
"@lcm//:lcm-python",
],
)

sh_test(
name = "demo_dry_run_test",
size = "small",
Expand Down
18 changes: 11 additions & 7 deletions automotive/steering_command_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ class bcolors:
ENDC = '\033[0m'


def make_driving_command(throttle, steering_angle):
msg = lcm_msg()
msg.acceleration = throttle
msg.steering_angle = steering_angle
return msg


class SteeringCommandPublisher:
def __init__(self, input_method, lcm_tag, joy_name):
print 'Initializing...'
Expand Down Expand Up @@ -208,19 +215,16 @@ def start(self):
else:
self.last_value = self.event_processor.processEvent(
event, self.last_value)
msg = lcm_msg()
msg.steering_angle = self.last_value.steering_angle
msg.acceleration = (self.last_value.throttle -
self.last_value.brake)
msg = make_driving_command(self.last_value.steering_angle,
self.last_value.throttle -
self.last_value.brake)
self.lc.publish(self.lcm_tag, msg.encode())
self.printLCMValues()


def publish_driving_command(lcm_tag, throttle, steering_angle):
lc = lcm.LCM()
last_msg = lcm_msg()
last_msg.accleration = throttle
last_msg.steering_angle = steering_angle
last_msg = make_driving_command(throttle, steering_angle)
lc.publish(lcm_tag, last_msg.encode())


Expand Down
28 changes: 28 additions & 0 deletions automotive/test/steering_command_driver_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import lcm
import unittest

from drake.lcmt_driving_command_t import lcmt_driving_command_t as lcm_msg
from drake.automotive.steering_command_driver import make_driving_command


class SteeringCommandDriverTest(unittest.TestCase):
def __init__(self, *args, **kwargs):
super(SteeringCommandDriverTest, self).__init__(*args, **kwargs)
self.lcm_tag = "EXAMPLE"
self.acceleration = 0.5
self.steering_angle = 0.2

def handler(self, channel, data):
msg = lcm_msg.decode(data)
self.assertEqual(msg.acceleration, self.acceleration)
self.assertEqual(msg.steering_angle, self.steering_angle)

def test_make_driving_command(self):
receiver = lcm.LCM()
subscription = receiver.subscribe(self.lcm_tag, self.handler)
sender = lcm.LCM()
sender.publish(self.lcm_tag,
make_driving_command(self.acceleration,
self.steering_angle).encode())
receiver.handle()
receiver.unsubscribe(subscription)

0 comments on commit 705e72b

Please sign in to comment.