Still the error is thrown and I'm getting hard time figuring it out

Respected Prof,
It’s still throwing this error, even though I reordered the arrangement as I was told.

Below is my code:
#! /usr/bin/env python

import rospy
from geometry_msgs.msg import Twist
from sensor_msgs.msg import LaserScan

def callback(msg):

rospy.init_node('topics_quiz_node', anonymous = True)
pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
sub = rospy.Subscriber('/kobuki/laser/scan', LaserScan, callback)

rate = rospy.Rate(2)
move = Twist()

def decide_direction(ranges):

    straight = ranges[360]
    left = ranges[719]
    right = ranges[0]

    if straight > 1:
    if (straight < 1) or (right < 1):
    if left < 1:

    def straight_motion():
        move.linear.x = 0.6
        move.angular.z = 0

    def turn_left():
        move.linear.x = 0
        move.angular.z = 0.2

    def turn_right():
        move.linear.x = 0
        move.angular.z = -0.2


Based on the code you have shared, you didn’t order them as indicated. All functions should move to the top of the file, just after the import statements.

1 Like

Yeah yeah Sir. I flagged it with a message. Really sorry. I couldn’t understand it before properly. By reading it over and over, I understood it.
Thanks a ton Professor @bayodesegun

1 Like