Tuesday, 28 June 2011

MidTerm Presentation

This morning, I did a midterm presentation of the project, with explainations about all the work done, and to be done.
If you want to see them, the slides are available in my google docs, in "Croquet Project Management" collection (contact me if you need access).

Thursday, 16 June 2011

Bluetooth

Today a little report about Bluetooth connection between NXT controller (Robot) and the computer.

After some tries which didn't work and some search, it appeared that the problem didn't come from the code, but from the Bluetooth protocol stack : indeed, Bluecove, which is the open source Java library used by LeJOS for bluetooth, doesn't support some Bluetooth protocol stack, including the one by Toshiba, which is the default one I had on my laptop.

Fortunately, the solution given by bluecove developers is to simply to replace it by the Microsoft one available for Windows, which works.

And actually, it seems to work!

Tuesday, 14 June 2011

Collisions ( Part II )

  • Change directions and speeds of the elements using mechanics 

 Directions


The f angle we found in the last part will enable us to find the new directions :

Indeed, by rotating it for 90°, we find the tangent of the collision ( black line on the figure ).
Then, the reflection law on this tangent gives you the new direction angle of the source element, which formula is :

newAngle =  2 * ( f + Pi/2 ) - b 

where f+Pi/2 is in radians the angle of tangent and b the initial direction angle of the source element.

 If the target element can me moved, then its direction is simply the angle f.

Speed

The formulas used to calculate new speeds are again the ones founded on this website :
http://amrita.vlab.co.in/?sub=1&brch=68&sim=197&cnt=1

So, in order to be able to calculate the momentums, the elements have know a mass parameter.

The following is a direct application of these mechanic formulas, so I'm not going to explain it here.

Collisions with the board

Two things must be programmed here :
  • Collision with sides
As the platform is supposed to represent the world, I chose, for the moment, to suppose that when an element goes out, the program replace it on the side of the board. So, there are no reflection law applied here, unless, for example, for pool game.
  • Friction forces on the board
The elements have also a friction coefficient as a parameter, which depends on their material, and the one of the board. I supposed the balls rolls without slipping, and so the only force active on the board is the ground reaction.
So, the fundamental princple of dynamics gives a constant acceleration of - g * f, where f is the friction coefficient, and g the constant of earth's gravity.
g has a value of 10, and I'll take 0.35 as friction value for ball/croquet ground, because this is within the range used for pool :
http://billiards.colostate.edu/threads/physics.html

Here ends the part about collision.

Collisions ( Part I )

Firstly, solid mechanics are very complex, and, depending on many elements such as shapes of elements, environmental factors, etc, differents laws are used to know what happen.
So, the code made for the platform limit mechanics to what is needed for croquet application : a ball which collides other balls and fixed elements.

In the code, each Element is now associated with a Shape object which Circle and Rectangle class heritate (some Elements like hoops may, however, be assiciated with more than one).
All the collisions aspects will be programmed into Shape objects.

Collisions between elements

This topic will be seperated into 3 part, which contain the needed elements to manage collisions :
  • Collision detection
  • Find the impact point and position the element on contact with the other
  • Change directions and speeds of the elements using mechanics

  • Collision detection

One of the model used by physic systems is to associate each element with a bounding box. The objective is to detect collisions between these bounding box. A bounding box can be a circle, a square rectangle, etc.. or even a more complex polygon. However, for each pair of shapes, it would be needed to program it.
Here again, I limited the platform to the needs of croquet : balls, peg, and extremities of hoops will be modelled as circle. To play the game, we'll also need to detect collision between ball's circle and hoop's rectangle.

Circle & Circle

You only need to compare the distance between centers with the sum of radius : if the distance is lower, there is collision.

Circle & Straight Rectangle

When rectangles are straight (this will be the case for hoops), the problem is not too complicated : two points have to be checked :

  1. If the circle's centre lies inside the rectangle
  2. If one of the edges of the rectangle intersects the circle

    • Find the impact point and position the element on contact with the other
     Here again, the platform is limited to collision between circles (we actually don't care about impact points when balls interesect hoop's rectangle, as it's not a "physic collision").

    Basically, the code is based on these geometric formulas :
    http://amrita.vlab.co.in/?sub=1&brch=68&sim=197&cnt=1

    As I use angles to model direction, instead of vectors, some adaptation was made.


    On this figure, you know the position of the source element before collision (St), the position of target (T).
    So, you can determine the angle a. Knowing the direction angle of source element gives you the angle b.
    Then, the difference of the angles and trigonemtry into XYZ triangles gives d value.
    To finish, you can find alpha into WYZ triangle, and deduce the value of f with the relation b-alpha .
    With f, you can then know the position of the element after collision.
    Rotating f of 90° also gives you the tangent angle I'll use in next part.

    Actually, many particular cases make the problem be more complicated.

    Thursday, 9 June 2011

    Robot & Camera

    At the same time I'm trying to make collisions work on the platform, I've also worked more on the LEGO Robot API ( so, considering planning, I made a part of next week work ).

    Robot Building
    •  Thor v2 : The hammer is now placed on the side, and wheels have been replaced. (last week version)
    •  Thor v3 : Similar to the last one, except that hammer is now hold better, so accuracy has increased a lot.
    ( I shall update CroquetRobotBuilding file soon to give more details and photos)

    Camera : Get a picture 

    This week I wanted to see how the program was going to request pictures from the camera.
    Firstly, I planned to use LTI-CIVIL Java library that enables requesting pictures from USB media devices.
    However, as the Edimax camera used is a network camera, it is not detected by the library, so I searched something else.

    And so after configuring the camera on the local network of the laptop, I realized that it's going to be a lot easier with it.
    Indeed, the camera sets direct snapshots on the network ( at the address http://cameraIP/snapshot.jpg ), so you just need the get and save an image from this URL each time you need one, before processing it.