Python exam robot_control_class doesn't contain rotate function

Hi there, the robot_control_class code that is given to us for python exam doesn’t contain rotate() function, can we use the previous robot_control_class( the one we use for getting turtlebot out of the maze) which contained the rotate function() or should we use turn() function instead which is available in given to us for the python exam. I think the rotate() is much better as it is precise. Alos, if we use the one containing roatate() function, will it cause any exam issues or not. Thanks and awaiting reply.

Hi @navjotsinghsodhi52 ,
It has been quite some time since I did the python course but I vaguely do remember encountering this issue.

You can create your own rotate() function instead of relying on the turn(). You can take inspiration from the original rotate() function from the robot_control_class that is given to you at the start of the course. The original class can be found at /home/simulations/public_sim_ws/src/all/ros_basics_examples/python_course_class

The rotate function can be implemented like this:

def rotate(self, degrees):
        target_rad = (degrees * math.pi/180) + self.yaw

        if target_rad < (- math.pi):
            target_rad = target_rad + (2 * math.pi)

        if target_rad > (math.pi):
            target_rad = target_rad - (2 * math.pi)

        while abs(target_rad - self.yaw) > 0.01:
            self.cmd.angular.z = 0.5 * (target_rad - self.yaw)


Happy Learning…!!


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