How to calculate distance travelled by Robot in avr - avr

Here, I want to calculate distance travelled by robot in atmega 2560? I know the formula distance = Wheel's circumference * motor's rotation in rpm. But I am not getting how to apply this formula for the following problem.
What is the approximate distance covered by the robot in 2 seconds, if OCR5AL=OCR5BL=0xB2. Given that, maximum speed at which the motors rotate is 300 rpm and wheels have a radius of 2.8cm.
Where
OCR5AL is Output compare register low value for Left Motor
OCR5BL is Output compare register low value for Right Motor
Maximum speed is attained, when OCR5AL =OCR5BL =0xFF.

Motor revolutions per minute (rpm) and wheel revolutions is something different. I do not think your robot's wheels rotate at 300 rpm.
So, in order to be able to calculate the distance, you need to know how many motor revolutions are needed for the wheel to rotate 360 degrees.
This would work fine if you have a stepper motor for instance. Knowing the amount of steps for the wheel to make a full turn gives you a math formula to calculate the distance.
If you want to approach this problem using time measurements, you need to figure out how many seconds and milliseconds it takes for the wheel to turn using different motor speeds.

Related

Finding fastest path for robotic drive base

I am trying to create an algorithm to find the fastest path a robot can take between 2 points in terms of time. The robot I would be using would be powered by a drive wheel on each side and have limited acceleration and velocity. I was also hoping to build in some obstacle avoidance so the robot is able to path around obstacles. I am familiar with pathfinding algorithms such as a* that find the fastest path in terms of distance between two points but this algorithm does not always find the fastest path for a robot with bounded acceleration and velocity.
I've been thinking about this for a couple days and honestly I'm not really sure where to start or where to find resources on the topic so any help is appreciated.
Example:
Lets say our robot is 10 units wide and each wheel has a maximum speed of 100 units/second and a maximum acceleration of 10 units/second/second.
At point A (x = 0, y = 0) the velocities of the robots wheels are 50 and 30 for the left and right wheels respectively and the robot is at a 30 degree angle relative to the x-axis. At point B (x = 1000, y = -600) we want the robot to be stationary and have a -75 degree angle relative to the x-axis
What is the most time efficient path for the robot to take from point A to point B given it's starting and ending velocities and headings while also avoiding the obstacles?

How to translate left and right motor speeds of a tank to a path/curvature

I'm working on a tank simulation in MATLAB. The tank has two motors, a left motor and a right motor. These can each be individually written to run at anywhere from (-100%) to (+100%) speed. So, if I write L, R = (100%, 100%), each motor will be spinning at the same speed and will therefore drive in a perfectly straight line. Writing L, R = (-100%, 100%) makes the robot stay in the same (x, y) coordinate, but changes its angle. L, R = (50%, 100%) makes the robot drive forward AND turn its angle.
My question: how can I translate these left and right motor speeds into a path or curvature equation?
Assuming no slip, the velocity of the tank will be the average of the speeds of the two engines. The rate of rotation will be directly proportional to the difference in speed of the two engines. If w is the width of the tank, and v_delta is the difference in distance traveled per second of the two sides, the tank will turn around once in 2 * PI * w / v_delta seconds so the turning rate is v_delta / 2 * PI * w rotations per second, or v_delta / w radians.
This gives you the velocity as a function of time. And now you can just track the location and angle of the tank just like you would any other moving and accelerating object. (I personally would use Runge Kutta.)

How to calculate distance traveled given constant acceleration and initial speed

I have to do an animation, and I need a spinning wheel (constant speed), to start decelerating (constant acceleration) until it stops. I need to start the deceleration at the correct time so that the wheel stops exactly at a pre-determined position.
In other words, given an initial speed (for example, in pixels per second) and an acceleration value, I need to figure out the total distance travelled until the speed is 0.
Code can be any language, or pseudo-code, but preferably C.
Thank you.

Predictive Aiming in Tower Defense

I don't even know if it's mathematically feasible, but let's say I have a tower at (Tx, Ty) shooting at a monster located at (Mx(t),My(t)).
The thing is, the path followed by the monster is jagged and swirly, meaning that predictive aiming from a distance based on velocity/direction at -that exact time- would be useless. The monster would've changed directions two times over by the time the bullet reached its target.
To solve this, I have a function to fast forward the monster for (t) frames and get its position as (Mx(t), My(t)) assuming its velocity remains constant. I can get the monster's position at t = 0 (current position) or t = 99999, or anything in between. Think of it as a lookup table.
The hard part is having the turret predictably aim at a position derived from that function.
I have to know t beforehand to know what to put into (Mx(t), My(t)). I have to know (Mx(t), My(t)) to know the distance and calculate the t from that. Is this even possible? Are there alternatives?
Any kind of pseudocode is welcome.
It is, if I understand your problem correctly, basically the transformation for euclidian to polar coordinate system
If you have the relative position x=Mx(t)-Tx and y=My(t)-Ty which is
distance= sqrt(x^2+y^2)
phi = arctan(y/x)
this assumes infinite speed of the shoot. However you can first calculate the approximate time for the projectile using the current position. Calculate the flying time based on the estimated distance and iterate this process.
If convergence speed is to slow (not much difference in projectile/monster speed) You can also use the idea of Divide and conquer.
You calculate the maximum distance the monster runs if it maximises distance. Calculate the distance for now, the max distance and the middle. Then you can decide in which half the monster is and calculate again distance in the middle.
I think everything else would require more information on how you plan to calculate Mx(t) and My(t)
You want the atan2 function.
If the tower is at tx,ty and the monster's predicted position is mx, my then the angle of the tower's gun has to be:
angle = atan2(my - ty, mx - tx)
This should be available in most languages.
Distance is, of course:
square-root((my - ty)^2, (mx - tx)^2)
where ^2 is "squared".

Moving GPS position with a certain distance (in meters) in a known direction

I have some GPS sample data taken from a device. What I need to do is to "move" the data to the "left" by, let's say, 1 to 5 meters. I know how to do the moving part, the only problem is that the moving is not as accurate as I want it to be.
What I currently do:
I take the GPS coordinates (latitude, longitude pairs)
I convert them using plate carrée transformation.
I scale the resulting coordinates to the longitudinal distance (distance on x) and the latitudinal distance (distance on y) - imagine the entire GPS sample data is inside a rectangle being bound by the maximum and minimum latitude/longitude. I compute these distances using the formula for the Great Circle Distance between the extreme values for longitude and latitude.
I move the points x meters in the wanted direction
I convert back to GPS coordinates
I don't really have the accuracy I want. For example moving to the left by 3 meters means less than 3 meters (around 1.8m - maybe 2).
What are the known solutions for doing such things? I need a solution that deviates at most by 0.2-0.5 meters from the real point (not 1.2 like in the current case).
LATER: Is this kind of approach good? By this kind I mean to transform the GPS coordinates into plane coordinates and back to GPS. Is there other way?
LATER2: The approach of converting to a conformal map is probably the one that will be used. In case of a small rectangle, and since there are not roads at the poles probably Mercator will be used. Opinions?
Thanks,
Iulian
PS: I'm working on small areas - so imagine the bounding rectangle I'm talking about to have the length of each side no more than 5 kilometers. (So a 5x5km rectangle is maximum).
There are two issues with your solution:
plate carrée transformation is not conformal (i.e. angles are not preserved)
you can not measure distances along lat or lon that way since that are not great circles (approximately you are off by a factor cos(lat) for your x).
Within small rectangles you may assume that lon/lat can be linearly mapped to x/y pairs but you have to keep in mind that a "square" in lon/lat maps to a rectangle with aspect ratio of approx cos(lat)/1.

Resources