Skip to content

Commit 0a3c40c

Browse files
added error signal compatability
1 parent f4cbfc5 commit 0a3c40c

File tree

1 file changed

+21
-9
lines changed
  • ros2/TurtlebotController/turtlebot_vel_ctrl/turtlebot_vel_ctrl

1 file changed

+21
-9
lines changed

ros2/TurtlebotController/turtlebot_vel_ctrl/turtlebot_vel_ctrl/vel_ctrl.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,30 @@ def __init__(self):
2626
def camData_callback(self,msg_in):
2727
msg_out = Twist()
2828

29-
k = 1.0
30-
err_z = msg_in.data
29+
# no camera data is found. set velocity to zero
30+
if msg_in.data < -999.0:
31+
msg_out.linear.x = 0.0
32+
msg_out.linear.y = 0.0
33+
msg_out.linear.z = 0.0
3134

32-
ang_input = err_z * k
35+
msg_out.angular.x = 0.0
36+
msg_out.angular.y = 0.0
37+
msg_out.angular.z = 0.0
3338

34-
msg_out.linear.x = 0.1 #define constant speed
35-
msg_out.linear.y = 0.0
36-
msg_out.linear.z = 0.0
39+
#1 or both lanes are detected and error is send as usual
40+
else:
41+
k = 1.0
42+
err_z = msg_in.data
3743

38-
msg_out.angular.x = 0.0
39-
msg_out.angular.y = 0.0
40-
msg_out.angular.z = ang_input
44+
ang_input = err_z * k
45+
46+
msg_out.linear.x = 0.1 #define constant speed
47+
msg_out.linear.y = 0.0
48+
msg_out.linear.z = 0.0
49+
50+
msg_out.angular.x = 0.0
51+
msg_out.angular.y = 0.0
52+
msg_out.angular.z = ang_input
4153

4254
self.vel_publisher.publish(msg_out)
4355

0 commit comments

Comments
 (0)