|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools |
Rating:
|
Display Modes |
|
#13
|
||||
|
||||
|
Re: Mecanum Wheels & Encoders -- Java code
Quote:
First, learn how the mecanum drive classes actually map joystick inputs to individual motor powers and generate an equation describing them. Stick with linear control and it should be relatively simple to interpolate. For example, look at the constraints first: When JoyY1 = 1 and JoyX = 0, all four motors output "1" (for purposes of this exercise, reverse polarity on the opposing wheels due to gearbox orientation) When JoyY1 = -1 and JoyX = 0, all four motors output "-1" When JoyY1 = 0 and JoyX = 1, Front outputs "1" and rear outputs "-1" When JoyY1 = 0 and JoyX = -1, Rear outputs "-1" and front output "1" When JoyY1 = 1 and JoyX = 1, Front outputs "1" and rear outputs "0" ... etc etc Anyway, map the entire region on an XY plane and you can see how the X input and Y input varies each motor power. Note that they are dependent. Now, in your code you can record the X and Y input values, and calculate the "expected" motor output powers. Use your reference encoder to relate power vs rpm (say, 100 rpm = 0.7 power output) and calculate a "control" constant (although this could be a function and not a constant -- determine this by testing at different powers). C = 100/0.7 (or whatever units you want). For the rest of the wheels, read in encoder values and calculate new power ratios based on how different each wheel's power correlates to their rpm. 100 rpm / C = output power. If "output power" is exactly 0.7 here as well, the wheel speeds are equal. But since they're not due to friction or other reasons, you will need to generate new constants for each wheel. 100 rpm / C = 0.7 * constant that constant will be close to 1 -- maybe 0.95 if that particular wheel has less friction, 1.05 if it has more. Anyway, take this constant and bias the mecanum drive output: motor1.set(motor1_output*constant); That way, in the case where JoyY = 1 and JoyX = 0 (for example), Motor1 = 1 but Motor2 = 0.95, thus keeping the robot driving straight. Last thing -- you'd have to determine the "worst-case" motor, the one that performs the worst for a given output power, and use that as your limiting output power. Otherwise the less powerful wheel will saturate (above calc will be >1) and the power will truncate to 1. So all the constants to 3 motors should be <1, and the least effective motor is exactly 1. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|