# How to create a moving marker?

Hi, I would to get a simple cylinder moving from point A to B. I understand that i have to use tf transformations, so i tried following the tf tutorial but they use the turtle, and i couldn't relate to my problem. Is it necessary to have a python file for the broadcaster and the listener separated?

I first tried to create a tf in the starting point but i couldn't get it to show on rvizz.

I'm struggling to understand how to set the name of the frame id and the child id.

(The posicaoinicial function just set's the position and orientation)

    self.dummyid = id
self.listener = tf.TransformListener()
self.transform = Transform()

self.posinicial = posicaoinicial(self.transform)

self.br.sendTransform((self.posinicial.translation.x,self.posinicial.translation.y,self.posinicial.translation.z),(self.posinicial.rotation.x,self.posinicial.rotation.y,self.posinicial.rotation.z,self.posinicial.rotation.w),rospy.Time.now(),"dummie","world")

while not rospy.is_shutdown():
try:
(trans, rot) = self.listener.lookupTransform('dummie','world',rospy.Time(0))
except (tf.LookupException, tf.ConnectivityException, tf.ExtrapolationException):
continue


Thanks!!

edit retag close merge delete

Hi @ruipcosta,

To avoid a possible xyproblem can you post what you want to achieve with that?

In order to understand the problem and consider possible solutions.

( 2020-03-11 06:31:37 -0500 )edit

Hi @Weasfas ! I want to implement a velocity obstacle problem, so i'm scaling it down. I'd like to have two markers circle/cylinder (starting with just 1 to simplify) moving from point A (eg. x=-20, y = 0) to point B (eg. x=20, y=0) moving only on the xy plane. I wounder if i need to implement tf. When i get it moving i can subscribe to its position and do some calculations (but its not relevant for now). I'm having trouble implementing a sence of velocity (m/s). I don't know how to explain it better, if still have questions i'll try my best to answer.

( 2020-03-18 12:23:51 -0500 )edit

Hi @ruipcosta,

Are you sure you want to use a Marker? Rviz is only a visualization tool thus it cannot be used to model your problem, you may need another tool like Gazebo to do so.The marker element is merely a visualization entity, thus it cannot be use as an object/obstacle to operate with. At least nobody should do that since it is not its purpose.

If you want to implement a moving marker you only need to implement a marker publisher in a foor loop incrementing the marker pose in each cycle and using the lifetime parameter in the marker msg to clear old markers printed in Rviz.

However, if you want to use a more suitable approach, you can solve your problem just using Gazebo, adding an obstacle to the simualtion enviroment (E.g.: Cube) and using a plugin to move it whenever you want.

( 2020-03-18 16:18:44 -0500 )edit

@Weasfas i'm using it just for representation ofc. The marker is to represent an interation between a car and a moving obstacle... my question is do i have to use a tf? Sorry, i'm new to this, and didn't want to mess with gazebo as i get a feeling from readind around it is quite hard to use (never tried it) and since this is only for a demo (representation wise) i figured that could be done with markers

( 2020-03-18 16:28:58 -0500 )edit

@ruipcosta, To answer about the need of tf you willl need to think about the usage tf is supposed to provide. Do you have a tf tree? In this set up, you do not need to use a tf in order to move the marker, the tf is used to keep track of multiples coordinate frames within a operational space, giving you the possibility of knowing the pose and relative pose of several links in a specific time. The tf is just giving you the state of a coordinate frame, is not suposed to be used to move any object, for this you have msgs like Twist.

In the code, you are listening to a trasnformation between 'dummie' and 'world' and this frames probably do not exist. On the other hand, if you work with a real robot or a URDF model, in that case you will need to use ...(more)

( 2020-03-19 07:05:59 -0500 )edit

Hi @Weasfas, I will need tf to get the position between the 2 markers, think of the marker representing a car, i need to now its pose, to do calculations, hence the need of tf in my opinion (could be wrong). And since I'll need a tf i thought i could simply move it to represent the motion wanted. I didn't understand how to do a tf tree on the tf tutorials. I though that by sending a transform would do it.

In another unrelated question, i have a marker array (markerlist), can i simply erase a marker form that array using markerlist.remove(marker) and not do a Marker.action Delete ?

Thanks for all the help!!

( 2020-03-22 18:11:21 -0500 )edit

Hi @ruipcosta, as you said, if you think about the marker as a car, you need to know its pose, that information is provided by the the odometry (that can be a frame) but you do not need a tf between the car and the object because in reality you should not know where the obstacle is when the car is moving. I see this as trying to implement a collision avoidance algorithm in which you only have as inputs the car pose and its sensors data, able to detect obstacles. However, as you said in your comment, in a dummy environment, you can generate a transform between markers, listen to it and generate a relative transform to calcualte the relative distance between objects, but for this approach you will need something that tells you the "real" pose of each obstacle in order to generate properly the tf frames of each one.

( 2020-03-23 04:25:41 -0500 )edit