Hi there,
Absolutely loving the platform so far! Though, with the next rosject features added into the ROS basics in 5 courses i find myself stuck sometimes, and i really have a hard time getting anywhere, even with the given hints. I’m a Python novice, so bear with me.
Specifically, im stuck trying to make the turtlebot find the wall, move close to it, and then turn to be readu for the follow_wall program from part1. I’m able to get the turtlebot to find the nearest object and move towards it, but i think my code structure is really bad. Once i have the main code down for the movement, i’ll fix the the service calls last. This is what i have so far:
#!/usr/bin/env python
import rospy
from sensor_msgs.msg import LaserScan
from geometry_msgs.msg import Twist
def next_step(msg):
print("NEXT STEP HERE")
rospy.sleep(10)
def move_forward(msg):
step2_front_scan = msg.ranges[0]
print("Front scan: ", step2_front_scan)
print("--------------------------------------------")
rospy.loginfo("Moving towards wall!")
while step2_front_scan > 0.3:
print("Front_scan: ", step2_front_scan)
move.linear.x = 0.05
pub.publish(move)
move.linear.x = 0.0
pub.publish(move)
rospy.loginfo("Wall is now within target!")
next_step(msg)
def callback(msg):
front_scan = msg.ranges[0]
min_scan = min(msg.ranges)
a_front_scan = round(front_scan,1)
a_min_scan = round(min_scan,1)
print("Front scan: ", a_front_scan)
print("Minimal scan: ", a_min_scan)
print("--------------------------------------------")
if a_front_scan <= a_min_scan:
rospy.loginfo("Front is now facing wall!")
move.angular.z = 0.0
pub.publish(move)
move_forward(msg)
else:
move.angular.z = 0.1
pub.publish(move)
move = Twist()
laser_get = LaserScan()
rospy.init_node('obstacle_avoidance_node')
pub = rospy.Publisher("/cmd_vel", Twist, queue_size=10)
sub = rospy.Subscriber("/scan", LaserScan, callback)
rospy.spin()