-1

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

Bruce
  • 519
  • 6
  • 23

1 Answers1

1

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.

Paul R
  • 208,748
  • 37
  • 389
  • 560
  • I can get x,y position of ball with camera but how can i get x,y position of self (self is a my robot, doesn't it???) – Bruce Apr 17 '16 at 03:17
  • Well you have to calculate the distance *somehow* - if you can't track the location of the robot then you'll need to think of a different way of determining the distance from the ball. – Paul R Apr 17 '16 at 07:51
  • Do you have another way that i can track to ball with a fixed distance. Beause i use my camera (camera of android phone) and assemble in my robot. So it look like a eye of robot, it just see ball and get x,y position and radius of ball. So i don't know how can i get x,y position of my robot. Your mean is that i need another camera to see robot and get x,y position of robot??? – Bruce Apr 17 '16 at 14:07
  • There are an infinite number of ways of doing this, depending on what sensors you have available - one very crude way though would be to try and maintain the ball at the centre of the display and keep the ball diameter constant. – Paul R Apr 17 '16 at 15:25
  • Yes this is exactly question i want to ask, and problem i am facing. I have thought about that, maintain x,y at centre and keep diameter constant, i decide use PID algorithm to keep x,y of ball alway at centre, but now i have object with 3 input x,y diameter, and 2 output is duty percent, motor's direction. I afraid PID controller is not suitable for my issue and solve it because PID usually use for 1 input 1 output system. Could you please tell me the best way that i can maintain x,y position at centre and keep diameter no change , or which controller algorithm that help me solve this problem – Bruce Apr 17 '16 at 16:27
  • PID is probably overkill, at least initially - just start with a simple proportional control loop and see how that goes - you can always add the I and D terms later if needed. – Paul R Apr 17 '16 at 16:29
  • Could you please tell me more detail, i was try, but i can not use PID for both of x and y position. if it just alignes x position of ball to centre with PWM ,i can use PID for that. However, i have both of x and y posion and i need to control both of PWM and direction for 2 wheel. Do you have a another way or another controler – Bruce Apr 17 '16 at 17:36
  • You probably need to talk to your teacher or supervisor if this is a school project - without knowing all the details of your hardware and your project requirements I don't think anyone can help you. The question is way too broad as it stands anyway. If you have any *specific* programming questions later though, once you get started, then come back and ask them here on SO. – Paul R Apr 17 '16 at 18:31
  • 1
    Maybe i need to talk with my teacher. This is my project at school. Thank you so much for your help and advice. I so appreciate it. – Bruce Apr 18 '16 at 02:56