Need help in wallfind service

Hi, need help as robot does not move as service called,i am stuck here,need help pls

#! /usr/bin/env python

import rospy
from my_pkg.srv import FindWall, FindWallResponse
from time import sleep
from geometry_msgs.msg import Twist
from sensor_msgs.msg import LaserScan

found = False
tolerance = 0.02 # meters
fwd_done = False
parallel_done = False
min_value = 0.0
min_index = 0

move = Twist()

def laser_callback(msg):
front = msg.ranges[90]
right = msg.ranges[135]
left = msg.ranges[45]

global min_value, min_index
min_value = min(msg.ranges)  # find minimum value
min_index = msg.ranges.index(min_value)  # get location
print("min_value, min_index ", min_value, min_index)
move.linear.x = 0.05
move.angular.z = -0.01
while (True):
    if not fwd_done:
        if (front - 0.2) > tolerance:
            move.linear.x = 0.05
            move.angular.z = -0.01

    elif not parallel_done:
        if (right - 0.3) > tolerance+0.1:  # allow greater tolerance
            if min_index < 90:
                if msg.ranges[47] > msg.ranges[45]:
                    move.angular.z = 0.01

                    move.angular.z = -0.01

                if msg.ranges[47] > msg.ranges[45]:
                    move.angular.z = -0.01
                    move.angular.z = 0.01

            move.linear.x = 0.0
            parallel_done = True

        move.linear.x = 0.0
        move.angular.z = 0.01

def wallcallback(req):
found = True
req.wallfound = True
return FindWallResponse(req.wallfound)

sub = rospy.Subscriber(’/scan’, LaserScan, laser_callback)
pub = rospy.Publisher(’/cmd_vel’, Twist, queue_size=10)

def service_creation():
my_service = rospy.Service(“find_wall”, FindWall, wallcallback)
rospy.loginfo(“Service is Ready”)


In order to get help fast here, you should give sufficient information and not assume we know which exercise you are talking about:

  • Which course is it? Or is it a rosject? Are you working on The Construct or your local PC?
  • If it’s a course:
    • Which unit?
    • Which exercise?

Is your service server running?

Also, that is a pretty ugly copy/pase of your code, so it is hard to understand. Where is your main? I would use it instead of your service_creation() function

its rosject assignment

i updated my file…but how to place here?

Please be clearer, it is impossible to understand your problem if it is not explained.

  • What is your problem?
  • What is your setup like?
  • Add useful screenshots
  • Is your service server running?
  • Can you call the server through the terminal?

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.