I am working on an autonomous robot. This robot can recognize an object and pick it up. I have a pickup algorithm already. $$x=D\cos(θ) \quad \text{and} \quad y=D\sin(θ),$$ where $D$ is the length of my robot arm and $θ$ is the angle that it moved in radians.
This code gives an understanding of where the arm is on the Cartesian plane. I have an object detection system and using ultrasonic sensor I want it to stop $2 \,\text{cm}$ before the object. If the robot is located at the origin, $(0, 0)$, and the object is $2 \,\text{cm}$ from me, I want to know its $(x, y)$ coordinates. How do I convert from centimeters to degrees so I can know the object's $x$ and $y$ values?
You need one other piece of data. You know you are $2$ cm from the object but you have not told us you know what angle it is at. Without that it could be anywhere on a $2$ cm circle around your current point. It sounds like you are approaching it, so it can't be behind you but that still leaves a large range. You know $D=2$ but you have no data to evaluate $\theta$ in what you have given.