0
$\begingroup$

Rosanswers logo

Hello guys, I wrote a little python script to test moving the robot around in Gazebo, in which the robot just rotates around it z axis 5s clockwise and after that 5s counter clockwise in an while loop.

When i started my python script via rosrun move_pepper move_pepper.py i got following error:

pub = rospy.publisher('/pepper/cmd_vel', Twist, queue_size=1) AttributeError: 'module' object has no attribute 'publisher'

I dont really know what this means and i followed a tutorial in which very thing is the same

Here is my script code

#! /usr/bin/env python

import rospy

from geometry_msgs.msg import Twist

from time import sleep

rospy.init_node('movep')

pub = rospy.publisher('/pepper/cmd_vel', Twist, queue_size=1)

rotate_right = True

while not rospy.is_shutdown(): msg = Twist() msg.angular.z = 0.1 if rotate_right else -0.1

pub.publish(msg)

rotate_right = not rotate_right

sleep(5)

what do i need to do to get it running?


Originally posted by Qilos on ROS Answers with karma: 43 on 2020-10-20

Post score: 0


Original comments

Comment by Qilos on 2020-10-20:
i also dont know why it didnt properly show my code here, just the first and the last 3 lines

Comment by RobertZickler on 2020-10-20:
This has to do with indentation of the text. Try to indent with 5 times 'space'

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

You have to write rospy.Publisher(...). With a capital P

Like described here: http://wiki.ros.org/rospy/Overview/Publishers%20and%20Subscribers

Robert


Originally posted by RobertZickler with karma: 104 on 2020-10-20

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by Qilos on 2020-10-20:
Thank you very much that was the culprit

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.