This really is a non-trivial task you're trying to undertake. The challenge is reactive velocity control of the arm as opposed to deterministic goal based control. This is still an active research topic as far as I'm aware.
MoveIt has the ability to perform basic velocity control, but this will result in extreme behaviour near singularities which will throw your UR5 into safe mode. I have personal experience of doing exactly this.
Can you answer a couple of questions:
Are you using a wrist mounted camera or a statically mounted one?
Do you need the arm to follow the marker in real time?
Edit:
To implement real-time tracking you need to use velocity control of the arm. This is not too complicated to implement if you ignore the problem of singularities, I'll describe the theory below.
You'll need to create a control law that determines the desired angular and linear velocities of the end effector based upon the relative position of the marker. The velocity should be higher the further away the end effector is from its desired location, and you'll want a dead zone around the perfect position to avoid it oscillating around this.
Once you've got this desired velocity (twist message type), you'll need to get moveit to calculate the Jacobin matrix of the manipulator at its current location. This matrix can be used to translate the velocity of the end effector into a vector of joint velocities.
Now you simply pass these joint velocities to the UR driver to control the arm.
One limitation of this method is it will happily run straight into a singularity, solving that is a whole new problem. Hope this helps.
Hey Abdu, Did you ever get this working? I need to have my UR5 adjust its path from external force input and so is prob similar to impedance. I also need the robot to learn and generalize to similar situations but can't figure out how to get neural network output to publish data useful for Movit
hello,Abdu,how did you make the camera attached at the end effector. I am new for ROS .and i have been struggling in this for few weeks,can you give me some hints.Thank u very much!
@reallllljy I am not sure what do u mean, but I simply placed it at the end-effector of the manipulator.
Thanks for your reply,Abdu. Actually i don't how to place a camera at the end-effector. I guess it must be very easy for you, but its still a big problem for me,can u give me some hints? Thanks again
@reallllljy watch this video you can notice they attach a camera at the end of the arm, you can use normal webcam with usb-cable and attach it at the end
thanks a lot,i will figure it out