From 6242c59ee97d202a1381e265828e7018e537148a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ellensohn?= Date: Fri, 18 Aug 2023 10:39:52 +0200 Subject: [PATCH] optimize --- rmp220_middleware/rmp220_middleware.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/rmp220_middleware/rmp220_middleware.py b/rmp220_middleware/rmp220_middleware.py index 2465b0a..762bfbc 100644 --- a/rmp220_middleware/rmp220_middleware.py +++ b/rmp220_middleware/rmp220_middleware.py @@ -61,13 +61,11 @@ class StateMachineNode(Node): start_button = msg.buttons[7] # Joystick button 'start' select_button = msg.buttons[6] # Joystick button 'select' - # if self.state == State.DISABLED and msg.buttons[7] == 1: - if start_button == 1: # Joystick button 'start' + if start_button == 1: self.state = State.ENABLED self.get_logger().info("State: ENABLED (Button 'start')") self.enable_chassis() - # if self.state == State.ENABLED and msg.buttons[6] == 1: # Joystick button 'select' - if select_button == 1: # Joystick button 'select' + if select_button == 1: self.state = State.DISABLED self.get_logger().info("State: DISABLED (Button 'select')") self.disable_chassis() @@ -75,10 +73,13 @@ class StateMachineNode(Node): def cmd_vel_callback(self, msg): # This method shall only update the latest_cmd_vel attribute so it can be republished by the timer_callback with 100 HZ. Should have a look at performance though. self.latest_cmd_vel = msg + + # Will also derive the absolute values of the linear and angular velocity self.abs_x = abs(msg.linear.x) self.abs_z = abs(msg.angular.z) - self.timeout = 20.0 # Reset timeout when receiving commands + # Reset timeout when receiving commands + self.timeout = 20.0 def timer_callback(self): if self.state == State.ENABLED: