def scan_callback(data):
    laserscan_distance = LaserScanSplit()

    laserscan_distance.stamp = rospy.Time.now()

    distances = data.ranges
    array_len = len(distances)

    right_array = distances[0:array_len/3]
    laserscan_distance.rightMin = np.nanmin(right_array)

    center_array = distances[array_len/3:2*array_len/3]
    laserscan_distance.centerMin = np.nanmin(center_array)

    left_array = distances[2*array_len/3:]
    laserscan_distance.leftMin = np.nanmin(left_array)

    pub.publish(laserscan_distance)
Exemple #2
0
vel_msg = Twist()


def closing():
    # After the loop, stops the robot
    vel_msg.linear.x = 0
    vel_msg.linear.y = 0
    vel_msg.linear.z = 0
    vel_msg.angular.x = 0
    vel_msg.angular.y = 0
    vel_msg.angular.z = 0
    # Force the robot to stop
    velocity_publisher.publish(vel_msg)


distances = LaserScanSplit()


def scan_callback(data):
    global distances
    distances = data


def move():
    global distances
    # Starts a new node
    rospy.init_node('robotont_velocity_publisher', anonymous=True)

    rospy.Subscriber('/scan_to_distance', LaserScanSplit, scan_callback)

    vel_msg.linear.x = 0