Skip to content

Commit 3e89270

Browse files
committed
fixes
1 parent 65788b1 commit 3e89270

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

gr_navigation_managers/simple_crop_nav/simple_crop_nav.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ def __init__(self, desired_speed = 1.0):
2020
self.start = False
2121
self.forward = True
2222

23+
self.setPoses()
24+
#rospy.Timer(rospy.Duration(10), self.change_direction)
25+
rospy.Subscriber("/odometry/base_raw", Odometry, self.odom_cb)
26+
self.pub = rospy.Publisher("/nav_vel", Twist, queue_size=1)
27+
self.rb = utils.BagRecorder(desired_path = "/home/jose/ros_ws/src/gr_navigation/gr_navigation_managers/simple_crop_nav/data/",smach=False)
28+
29+
if self.forward:
30+
self.rb.startBag()
31+
32+
def setPoses(self):
2333
try:
2434
self.listener.waitForTransform('/odom', '/base_link', rospy.Time(), rospy.Duration(2.0))
2535
(trans,rot) = self.listener.lookupTransform('/odom', '/base_link', rospy.Time())
@@ -29,44 +39,43 @@ def __init__(self, desired_speed = 1.0):
2939
endpose = PoseStamped()
3040
endpose.header.frame_id = "base_link"
3141
endpose.pose.orientation.w = 1.0
32-
endpose.pose.position.x = 10.0
42+
if self.forward:
43+
endpose.pose.position.x = 10.0
44+
else:
45+
endpose.pose.position.x = -10.0
3346
p_end = self.listener.transformPose("odom", endpose)
3447
self.endpose = [p_end.pose.position.x, p_end.pose.position.y]
3548
except (tf.LookupException, tf.ConnectivityException, tf.ExtrapolationException):
3649
sys.exit()#continue
37-
#rospy.Timer(rospy.Duration(10), self.change_direction)
38-
rospy.Subscriber("/odometry/base_raw", Odometry, self.odom_cb)
39-
self.pub = rospy.Publisher("/nav_vel", Twist, queue_size=1)
40-
self.rb = utils.BagRecorder(desired_path = "/home/jose/ros_ws/src/gr_navigation/gr_navigation_managers/simple_crop_nav/data/",smach=False)
4150

42-
if self.forward:
43-
self.rb.startBag()
4451

4552
def odom_cb(self, msg):
4653
self.currentpose[0] = msg.pose.pose.position.x
4754
self.currentpose[1] = msg.pose.pose.position.y
4855
self.start = True
4956

50-
def is_finished(self):
57+
def is_running(self):
5158
return self.current_motions < self.max_motions
5259

5360
def publish(self):
5461
self.pub.publish(self.twist)
62+
print math.sqrt(math.pow(self.endpose[0] - self.currentpose[0],2) + math.pow(self.endpose[1] - self.currentpose[1],2))
5563

56-
if self.forward:
57-
if math.sqrt(math.pow(self.endpose[0] - self.currentpose[0],2) + math.pow(self.endpose[1] - self.currentpose[1],2)) < 0.5:
58-
self.change_direction()
59-
else:
60-
if math.sqrt(math.pow(self.startpose[0] - self.currentpose[0],2) + math.pow(self.startpose[1] - self.currentpose[1],2)) < 0.5:
61-
self.change_direction()
64+
if math.sqrt(math.pow(self.endpose[0] - self.currentpose[0],2) + math.pow(self.endpose[1] - self.currentpose[1],2)) < 0.5:
65+
self.change_direction()
6266

6367
def change_direction(self):
6468
self.twist.linear.x = -self.twist.linear.x
6569
self.forward = not self.forward
6670
print ("chnage direction forward ", self.forward)
6771
self.current_motions = self.current_motions + 1
6872

73+
self.setPoses()
74+
6975
if not self.forward:
7076
self.rb.close()
7177
else:
72-
self.rb.restart("test", str(self.current_motions), close_required = False)
78+
if self.is_running():
79+
self.rb.restart("test", str(self.current_motions), close_required = False)
80+
else:
81+
self.rb.close()

gr_navigation_managers/simple_crop_nav/simple_crop_nav_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
rospy.init_node("simple_crop_nav_controller")
77
controller = SimpleCropNavController()
88

9-
while not rospy.is_shutdown() and controller.is_finished():
9+
while not rospy.is_shutdown() and controller.is_running():
1010
controller.publish()
1111
rospy.sleep(0.1)
1212
rospy.loginfo("FINISHED")

0 commit comments

Comments
 (0)