ctrackingrobotics

how robot tracking ball with fixed distance?


I am tracking ball with camera in my android phone and send x,y position,radius of ball (x,y position is a pixel in screen android phone ) to my stm32f board via bluetooth. I assemble my phone and stm32f1 kit in a mobile robot. Now i would like my robot move to ball with a fixed distance.

Ex: I set distance 10cm. When i move ball forward, my robot forward to ball and always keep 10cm from robot to ball


Solution

  • Here is some pseudo code to get you started:

    while (TRUE) do
        get x, y position of ball
        get x, y position of self
        calculate distance between self and ball (hint: use Pythagoras)
        if (distance < 10 cm)
            move away from ball
        else if (distance < 10 cm)
            move towards ball
    end
    

    Now all you have to do is code this up in C.