View Single Post
  #2   Spotlight this post!  
Unread 12-07-2013, 23:19
magnets's Avatar
magnets magnets is offline
Registered User
no team
 
Join Date: Jun 2013
Rookie Year: 2012
Location: United States
Posts: 748
magnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond repute
Re: Math and Programming Behind Swerve

This depends on how the modules are driven. For the sake of this post, I am assuming that you are talking about independently steered and driven modules. There are several different ways to calculate the angles and speeds of each wheel, but the goal is to first find the point around which the robot is turning (it can be inside or outside the frame perimeter), then make sure all the wheels are tangent to a circle that has a center point on the robot turning point, and intersects the wheel. Then, based on the circumference of these circles, you must adjust the speed of each wheel so that the one that travels the farthest distance travels faster (like a differential on a car).

This can be calculated by adding the rotation to the xy movement for each wheel. To find the xy movement, you must first convert the xy to polar coordinates. r = sqrt(x^2+y^2), and theta = atan2(y, x) (note- some software reverses the order of the arguments for atan2 like excel, but LabView, Java, and C++ are like this)

R will be your wheel speed, and theta will be the wheel angle.
Then, you need to normalize r, because it can have a max value of sqrt(2) (at 1,1)
Then, it needs to be converted back to xy so that it can be added to the rotational part.

To find the rotational part, you need to know where the wheels are located relative to the center of the robot like on a coordinate plane so you have x and y coordinates for each wheel. Then, you need to convert these to polar coordinates, add 90 degrees to theta (so that wheels will be like /\)
\/
and multiply r by the desired rotation (this will cause the wheels farther from the center to spin faster so they can travel farther). Take these modified coordinates, convert to xy, add to the translation part, convert back to polar, and you will have your setpoints for wheel speed and angle.


To see a good implementation of programming swerve in java/c++ see Ether's post and look at the very top and very bottom ones.

As for LabView, check out 1094's post here.
Reply With Quote