Turtlebot just stops moving even with the code executing

asked 2019-12-04 05:45:32 -0600

Hi! I am an Electrical Engineering student that really likes robotics. So I took up a class that tackled turtlebots. So below is a of my first code that in a given square space the bot would find the center. And I am using python as the programming language

Let me give a short explanation so basically I defined a function that would estimate values given a certain tolerance level. I know that python 3 already has a pre defined function that does exactly that but the OS(ubuntu) I was using somehow does not have that function, being a newbie I opt not meddle with the libraries and just decided to define a function. Any how the code estimates the distance in front of it and behind of it to tell whether to move forward. Also the code estimates the bots yaw to tell what direction to turn (towards the center).

if isclose(self.yaw,-1.56,0.0,0.3) or isclose(self.yaw,1.56,0.0,0.3) and not (isclose(self.yaw,0.0,0.0,0.3) or isclose(self.yaw,3.12,0.0,0.3)):  
            if not isclose(msg.ranges[0], msg.ranges[180],0.0, 0.2) and (isclose(self.yaw,0.0,0.0,0.15) or isclose(self.yaw,3.12,0.0,0.15) or isclose(self.yaw,-1.56,0.0,0.15) or isclose(self.yaw,1.56,0.0,0.15)):
                print('WAT') 
                move.linear.x=0.1
                move.angular.z=0.0
            elif not isclose(msg.ranges[90], msg.ranges[270],0.0, 0.2) and isclose(self.yaw,-1.56,0.0,0.9) and msg.ranges[90] > msg.ranges[270]:
                print('WAT1')
                move.linear.x=0.0
                move.angular.z=0.5*(math.radians(90)-self.yaw)
            elif not isclose(msg.ranges[90], msg.ranges[270],0.0, 0.2) and isclose(self.yaw,-1.56,0.0,0.9) and msg.ranges[90] < msg.ranges[270]:
                print('WAT2')
                move.linear.x=0.0
                move.angular.z=-0.5*(math.radians(90)-self.yaw) 
            elif not isclose(msg.ranges[90], msg.ranges[270],0.0, 0.2) and isclose(self.yaw,1.56,0.0,0.9) and msg.ranges[90] > msg.ranges[270]:
                print('WAT3')
                move.linear.x=0.0
                move.angular.z=0.5*(math.radians(90)-self.yaw)
            elif not isclose(msg.ranges[90], msg.ranges[270],0.0, 0.2) and isclose(self.yaw,1.56,0.0,0.9) and msg.ranges[90] < msg.ranges[270]:
                print('WAT4')
                move.linear.x=0.0
                move.angular.z=-0.5*(math.radians(90)-self.yaw) 
            else:
                move.linear.x=0.0
                move.angular.z=0.0

This part seems to be problematic since during simulations I could see from the terminal that 'WAT3' prints but the bot does not move. A similar part of my code works just fine the difference with this is just ... (more)

edit retag flag offensive close merge delete

Comments

Skimming over the code I do not see where the message actually gets published. Could you perhaps post a link to the complete code? Furthermore, you talk also noted that you reimplemented a Python 3 function, as it was not working, this is due to ROS using your systems Python 2.7.

davekroezen gravatar imagedavekroezen ( 2019-12-04 06:39:06 -0600 )edit