Ask Your Question
0

python code can replace a command line?

asked 2018-11-01 10:50:47 -0500

asmigox gravatar image

anybody can help me with a crossroads that i need to solve. I have a code in python, it receives msg laserscan and transform to pcl, inside the same code need to controller a servo. it moves the hokuyo laser after 400 msg recive to another position, need a 3 or 4 positions 0-180 degrees. After it has 3-4 position return to original position and so successively, i know that with a launch file i could move the servo or command line too. the questions is. I could move servo publishing new position in python code using rosserial. tnx for read and hope someone can help with it.

edit retag flag offensive close merge delete

Comments

This is definitely possible, but the question is how are you controlling the servo? Does it have it's own dedicated node at the moment. What commands in roslaunch would you use to move it?

PeteBlackerThe3rd gravatar imagePeteBlackerThe3rd ( 2018-11-01 10:55:29 -0500 )edit
  1. the servo is conect to arduino mega
  2. start with a launch, <node pkg="" type="" name="" args="pub servo std_msgs/UInt16 130"/> and go on with a loop that i used to have inside the arduino script , but now i think that loop must be empty.
  3. self.motor_Pub = rospy.Publisher(). node
asmigox gravatar imageasmigox ( 2018-11-01 11:34:39 -0500 )edit

the node is inside the class that i created for the msg laserscan

asmigox gravatar imageasmigox ( 2018-11-01 11:35:44 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-11-02 07:08:51 -0500

If I understand you correctly you have a node which controls the servo and listens to the topic servo which has type std_msgs/Uint16. Messages published to this topic will control the position of the servo. Is this correct?

In this case you should be able to create a publisher to this topic within your lidar node which simply publishes a new std_msgs/Uint16 message whenever you need to move the servo. It is best to use two nodes one which directly connects to the servo via the arduino and another which processes the lidar data, and connect them using the topic. This way you keep the different functionality in separate nodes, you don't want to directly control the servo from the same node that's processing the lidar data.

Hope this makes sense.

edit flag offensive delete link more

Comments

maybe u are rigth when you said that i should create 2 nodes. i put all in one and everything run, but i have an error. IT says Uint16 object has no attribute 'ranges'. but what i did works. tnx again

asmigox gravatar imageasmigox ( 2018-11-02 15:40:20 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-11-01 10:50:47 -0500

Seen: 31 times

Last updated: Nov 02 '18