Skip to content

Commit

Permalink
upd api + mec
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJeffreyKuo committed Feb 14, 2024
1 parent b3107e7 commit 6a884a2
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 84 deletions.
1 change: 1 addition & 0 deletions pages/_meta.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"index": "JellyDocs",
"api-reference": "API Reference",
"programming": "Programming",
"resources": "Resources"
}
8 changes: 8 additions & 0 deletions pages/api-reference/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"linearopmode": "LinearOpMode",
"hardwaremap": "HardwareMap",
"gamepad": "Gamepad",
"motors": "Motors",
"servo": "Servos",
"crservo": "CRServos"
}
2 changes: 1 addition & 1 deletion pages/api-reference/gamepad.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@

## Notes

- Analog sticks are represented as floats that range from `-1.0 to +1.0`. They will be `0.0` while at rest.
- Analog sticks are represented as floats that range from `-1.0 to 1.0`. They will be `0.0` while at rest.
- Triggers are represented as floats that range from `0.0 to 1.0`. They will be at 0.0 while at rest.
- Buttons are boolean values. Returns `true` if pressed, otherwise it returns `false.
117 changes: 34 additions & 83 deletions pages/programming/robotics-framework/mecanum-teleop.mdx
Original file line number Diff line number Diff line change
@@ -1,114 +1,65 @@
# Mecanum TeleOp

## Understanding Mecanum Wheels

#### 1. Design and Structure:
## Mecanum Wheels

- **Unique Configuration**: Mecanum wheels have unique rollers positioned at a 45-degree angle around the wheel.

#### 2. Movement Mechanics:

- **Holonomic Movement**: These wheels enable a robot to move in any horizontal direction without changing the wheels' or robot's orientation.
- **Vector Force**: Rotating Mecanum wheels generate a 45-degree force vector, combining to move the robot.

#### 3. Wheel Arrangement:

- **X Configuration**: The wheels are mounted to form an 'X' pattern when viewed from above, crucial for omnidirectional movement.

![Image](/assets/mecanumDirections.png)

### Mecanum Wheel Coding

Understanding Mecanum wheel control involves translating gamepad inputs into motor movements for omnidirectional mobility.

#### Basic Tank Drive Control

1. **Forward/Backward Movement**:

- **Gamepad Y Axis**: Controls forward and backward movement.
- **Motor Power Assignment**: Motor power is set based on the Y-axis value.
- **Reversing Y-Axis**: The Y-axis is often reversed in control systems.

```java
// Basic Forward/Backward Movement Control
double speed = -gamepad1.left_stick_y; // Inverting Y-axis value
## Mecanum Wheel Control

// Setting motor powers for forward/backward motion
leftMotor.setPower(speed);
rightMotor.setPower(speed);
```
y = forward velocity (forward/backward)
x = strafe velocity (left/right)
r = rotational velocity

2. **Adding Rotation (Pivot Turning)**:
frontLeftMotor = y + x + r
backLeftMotor = y - x + r
frontRightMotor = y - x - r
backRightMotor = y + x - r

- **Gamepad X Axis**: Controls rotation.
- **Power Adjustment for Rotation**: Differential power adjustments cause the robot to turn.
## Deriving Mecanum Wheel Control

```java
// Adding Rotation (Pivot Turning) Control
double speed = -gamepad1.left_stick_y; // Inverting Y-axis value
double rotate = gamepad1.right_stick_x; // Right stick X-axis for rotation
Let break the down to understand it

// Adjusting motor powers for rotation
leftMotor.setPower(speed + rotate);
rightMotor.setPower(speed - rotate);
```
Motors = y

#### Mecanum Wheel Control
![Image](/assets/forward_backward.png)

1. **Omnidirectional Movement**:
Forward/Back movement is obvious, however, there are still a few things to note.
Remember that joysticks have an interval of `-1 to 1`
Motors moves counterclockwise so you want to reverse the y direction:
`double y = -gamepad1.left_stick_y;`

- **Left Stick X Axis for Strafing**: Controls sideways movement.
- **Wheel Power Calculation**: Combines speed, strafe, and rotation values.
- **Diagonal Wheel Coordination**: Determines the direction of strafing.
leftMotors = y+r
rightMotors = y-r

```java
// Mecanum Wheel Omnidirectional Movement Control
double speed = -gamepad1.left_stick_y; // Forward/Backward (Y-axis)
double strafe = gamepad1.left_stick_x; // Strafing (X-axis)
double rotate = gamepad1.right_stick_x; // Rotation (right stick X-axis)
Now in our current form, we have a differential drive/tank drive, enabling differential steering.

// Calculating motor powers for omnidirectional movement
frontLeftMotor.setPower(speed + strafe + rotate);
backLeftMotor.setPower(speed - strafe + rotate);
frontRightMotor.setPower(speed - strafe - rotate);
backRightMotor.setPower(speed + strafe - rotate);
```
![Image](/assets/rotation.png)

2. **Control Equations**:
If both sticks are pushed at the same time, it will cause the robot to move in a curve
leftMotors = 1+1 = 2 (Clipped to 1)
rightMotors = 1-1 = 0

- **Direction and Speed**: `speed` controls forward/backward, `strafe` controls sideways movement, and `rotate` adds rotation.
![Image](/assets/curve.png)

3. **Motor Spin Direction**:
We add the final x value to enable omnidirectional movement based on the direction of the vector forces for each wheel.

- **Default Spin**: FTC motors typically spin counterclockwise with positive power.
- **Gear Configuration**: Gears can change the effective direction of motor rotation.
frontLeftMotor = y + x + r

4. **Code Improvements**:
![Image](/assets/FL.png)

- **Strafing Accuracy**: Multiplying `strafe` by a factor like 1.1.
- **Power Scaling**: Ensuring motor power values stay within -1 to 1 range.
backLeftMotor = y - x + r

```java
// Code Improvements for Strafing Accuracy and Power Scaling
double speed = -gamepad1.left_stick_y; // Forward/Backward (Y-axis)
double strafe = gamepad1.left_stick_x * 1.1; // Improved strafing (X-axis, scaled)
double rotate = gamepad1.right_stick_x; // Rotation (right stick X-axis)
![Image](/assets/BL.png)

// Scaling motor powers to maintain ratio and limit within [-1, 1]
double denominator = Math.max(Math.abs(speed) + Math.abs(strafe) + Math.abs(rotate), 1);
double frontLeftPower = (speed + strafe + rotate) / denominator;
double backLeftPower = (speed - strafe + rotate) / denominator;
double frontRightPower = (speed - strafe - rotate) / denominator;
double backRight
frontRightMotor = y - x - r

Power = (speed + strafe - rotate) / denominator;
// Setting the scaled motor powers
frontLeftMotor.setPower(frontLeftPower);
backLeftMotor.setPower(backLeftPower);
frontRightMotor.setPower(frontRightPower);
backRightMotor.setPower(backRightPower);
```
![Image](/assets/FR.png)

```
backRightMotor = y + x - r

```
![Image](/assets/BR.png)
Binary file added public/assets/BL.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/BR.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/FL.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/FR.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/curve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/forward_backward.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/rotation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6a884a2

Please sign in to comment.