Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/content/docs/hardware/actuators/cr-servos.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ There are two ways to construct a `NextCRServo`, depending on what you desire.
<TabItem label="Kotlin">

```kotlin
val intakeServo = NextCRServo(RobotController.controlHub, 0) // By Lynx Module and port, recommended
// By Lynx Module and port, recommended
val intakeServo = NextCRServo(RobotController.controlHub, 0)

val intakeServo = NextCRServo("intakeServo") // Using your configuration name
// Using a configuration name
val intakeServo = NextCRServo("intakeServo")
```

</TabItem>
<TabItem label="Java">

```java
NextCRServo intakeServo = new NextCRServo(RobotController.getControlHub(), 0); // By Lynx Module and port, recommended
// By Lynx Module and port, recommended
NextCRServo intakeServo = new NextCRServo(RobotController.getControlHub(), 0);

NextCRServo intakeServo = new NextCRServo("intakeServo"); // Using your configuration name
// Using a configuration name
NextCRServo intakeServo = new NextCRServo("intakeServo");
```

</TabItem>
Expand Down
19 changes: 12 additions & 7 deletions src/content/docs/hardware/actuators/feedback-servos.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,28 @@ All of these below are interchangeable with `NextFeedbackCRServo`.
<TabItem label="Kotlin">

```kotlin
val armServo = NextFeedbackServo("armServo", AnalogFeedback(name = "armEncoder")) // By configuration name
// By configuration name
val armServo = NextFeedbackServo("armServo", NextAnalogInput("armEncoder"))

val armServo = NextFeedbackServo(RobotController.expansionHub, 0, AnalogFeedback(name = "armEncoder")) // By Lynx Module and port

val armServo = NextFeedbackServo(RobotController.expansionHub, 0, NextAnalogInput(RobotController.expansionHub, 0)) // Full LynxModule
// By Lynx Module and port + NextAnalogInput
val armServo = NextFeedbackServo(RobotController.expansionHub, 0, NextAnalogInput("armEncoder"))

// Additionally, using a custom feedback method
val armServo = NextFeedbackServo("armServo", AnalogFeedback(voltageSupplier = { /* custom method here */ } ))
```

</TabItem>
<TabItem label="Java">

```java
NextFeedbackServo armServo = new NextFeedbackServo("armServo", new AnalogFeedback("armEncoder")); // By configuration name
// By configuration name
NextFeedbackServo armServo = new NextFeedbackServo("armServo", new NextAnalogInput("armEncoder"));

NextFeedbackServo armServo = new NextFeedbackServo(RobotController.getExpansionHub(), 0, new AnalogFeedback("armEncoder")); // By Lynx Module and port
// By Lynx Module and port
NextFeedbackServo armServo = new NextFeedbackServo(RobotController.getExpansionHub(), 0, new NextAnalogInput("armEncoder"));

NextFeedbackServo armServo = new NextFeedbackServo(RobotController.getExpansionHub(), 0, new NextAnalogInput(RobotController.getExpansionHub(), 0)); // Full LynxModule
// Additionally, using a custom feedback method
NextFeedbackServo armServo = new NextFeedbackServo("armServo", new AnalogFeedback(() -> { /* custom method here */ };
```

</TabItem>
Expand Down
224 changes: 224 additions & 0 deletions src/content/docs/hardware/actuators/motors.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
---
title: Motors
description: Control motors with NextMotor
sidebar:
order: 1
---

import { Tabs, TabItem } from '@astrojs/starlight/components';

`NextMotor` is a lightweight wrapper around the standard FTC motor (`DcMotor` or `DcMotorEx`) that provides standard easy-to-use interface for throttling, voltage control, PIDS, and more

## Creating a NextMotor
There are two main ways to construct a `NextMotor`, depending on what you desire.

<Tabs syncKey="language">
<TabItem label="Kotlin">
```kotlin
// By Lynx Module and port, recommended
val intakeMotor = NextMotor(RobotController.controlHub, 0)

// Using a configuration name
val intakeMotor = NextMotor("intakeMotor")
```
</TabItem>
<TabItem label="Java">
```java
// By Lynx Module and port, recommended
NextMotor intakeMotor = new NextMotor(RobotController.getControlHub(), 0);

// Using a configuration name
NextMotor intakeMotor = new NextMotor("intakeMotor");
```
</TabItem>
</Tabs>

All constructors accept two optional parameters:

| Parameter | Type | Default | Description |
|---|---|---|---|
| `anglePerCount` | `Angle` | 1.0 rad | The angle that a motor's shaft rotates by for every 'tick' or 'count'. Used for calculations that directly convert 'ticks' to the number of rotations the motor has spun. |
| `cacheTolerance` | `Double` | `0.01` | Minimum change in `throttle` required before a new value is written to the motor. |

## Usage
### Throttle Control

Throttle Control allows the motor to be throttled from -1.0 (reverse) to 1.0 (full power).
The value represents a fraction of the robot's total voltage.

<Tabs syncKey="language">
<TabItem label="Kotlin">
```kotlin
// Adjust 1.0 to be what value you would like it to be
myMotor.throttle = 1.0
```
</TabItem>
<TabItem label="Java">
```java
// Adjust 1.0 to be what value you would like it to be
myMotor.setThrottle(1.0)
```
</TabItem>
</Tabs>

### Voltage Control

Voltage Control allows the motor's power to be controlled more accurately and set to a specific voltage.

<Tabs syncKey="language">
<TabItem label="Kotlin">
```kotlin
// This function takes in a 'Voltage'
myMotor.voltage = 12.0.volts
```
</TabItem>
<TabItem label="Java">
```java
// This function takes in a 'Voltage'
myMotor.setVoltage(volts.of(12))
```
</TabItem>
</Tabs>

### Positional Control

Positional control allows the motor's position to be controlled using a `PID` Controller

You can change the default positional PID constants by doing:

<Tabs syncKey="language">
<TabItem label="Kotlin">
```kotlin
myMotor.positionConstants.apply {
kP = 0.1
}
// Like kP, other positional PID constants include:
// kP, kI, kD, kS, kV, kA, kG, kCos, kCosRatio
```
</TabItem>
<TabItem label="Java">
```java
myMotor.getPositionConstants()
.withP(0.1)
// Like kP, other positional PID constants include:
// kP, kI, kD, kS, kV, kA, kG, kCos, kCosRatio
```
</TabItem>
</Tabs>

#### Relative Positional Control
This moves the motor to the designated position **relative** to the position of the motor during the robot's startup.

<Tabs syncKey="language">
<TabItem label="Kotlin">
```kotlin
// Increase the target to be your desired angle from the initial position
myMotor.setPositionSetpoint(90.degrees)
```
</TabItem>
<TabItem label="Java">
```java
// Increase the target to be your desired angle from the initial position
myMotor.setPositionSetpoint(degrees.of(90))
```
</TabItem>
</Tabs>

#### Absolute Positional Control
This makes the motor take the shortest path, regardless of rotations to an angle in the range [-180, 180] degrees.

<Tabs syncKey="language">
<TabItem label="Kotlin">
```kotlin
// Increase the target to be your desired angle
myMotor.setAbsolutePositionSetpoint(90.degrees)
```
</TabItem>
<TabItem label="Java">
```java
// Increase the target to be your desired angle
myMotor.setAbsolutePositionSetpoint(degrees.of(90))
```
</TabItem>
</Tabs>

### Velocity Control
Similar to [Positional Control](#positional-control) velocity control allows the motor's velocity to be controlled using a `PID` Controller

<Tabs syncKey="language">
<TabItem label="Kotlin">
```kotlin
// Increase the target to be your desired angular velocity
myMotor.setVelocitySetpoint(30.degreesPerSecond)
```
</TabItem>
<TabItem label="Java">
```java
// Increase the target to be your desired angular velocity
myMotor.setVelocitySetpoint(DegreesPerSecond.of(30))
```
</TabItem>
</Tabs>

You can change the default velocity PID constants by doing:

<Tabs syncKey="language">
<TabItem label="Kotlin">
```kotlin
myMotor.velocityConstants.apply {
kP = 0.1
}
// Like kP, other velocity PID constants include:
// kP, kI, kD, kS, kV, kA
```
</TabItem>
<TabItem label="Java">
```java
myMotor.getVelocityConstants()
.withP(0.1)
// Like kP, other velocity PID constants include:
// kP, kI, kD, kS, kV, kA
```
</TabItem>
</Tabs>

### Following other motors
`NextMotor`'s have a helpful feature that allows one motor to 'follow' or mimic another motor.

You can use this feature by doing:
<Tabs syncKey="language">
<TabItem label="Kotlin">
```kotlin
myFollowerMotor.follow(myLeaderMotor)

// Optional direction to specify whether it should follow in the same
// or opposite direction.
myFollowerMotor.follow(myLeaderMotor, Direction.REVERSE)
```
</TabItem>
<TabItem label="Java">
```java
myFollowerMotor.follow(myLeaderMotor)

// Optional direction to specify whether it should follow in the same
// or opposite direction.
myFollowerMotor.follow(myLeaderMotor, Direction.REVERSE)
```
</TabItem>
</Tabs>

### `Direction`
You can set the `Direction` property of `NextMotor`'s to control the direction that the motor rotates in.

| Direction Type | Description |
|---|---|
| Direction.FORWARD | The motor moves forward (Clockwise) |
| Direction.REVERSE | The motor spins in the opposite direction (Counter-Clockwise) |

### `ZeroPowerBehaviour`
The `ZeroPowerBehaviour` property allows you to control how the motor reacts when it is given a `throttle` of 0

| ZeroPowerBehaviour Type | Description |
|---|---|
| ZeroPowerBehaviour.BRAKE | Actively stops the motor when given a power of 0 |
| ZeroPowerBehaviour.FLOAT | Allows the motor to naturally spin and eventually stop by itself |
14 changes: 9 additions & 5 deletions src/content/docs/hardware/actuators/servos.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,28 @@ import { Tabs, TabItem } from "@astrojs/starlight/components";

## Creating a NextServo

There are three ways to construct a `NextServo`, depending on what you desire.
There are two main ways to construct a `NextServo`, depending on what you desire.

<Tabs syncKey="language">
<TabItem label="Kotlin">

```kotlin
val armServo = NextServo(RobotController.controlHub, 0) // By Lynx Module and port, recommended
// By Lynx Module and port, recommended
val armServo = NextServo(RobotController.controlHub, 0)

val armServo = NextServo("armServo") // Using your configuration name
// Using a configuration name
val armServo = NextServo("armServo")
```

</TabItem>
<TabItem label="Java">

```java
NextServo armServo = new NextServo(RobotController.getControlHub(), 0); // By Lynx Module and port, recommended
// By Lynx Module and port, recommended
NextServo armServo = new NextServo(RobotController.getControlHub(), 0);

NextServo armServo = new NextServo("armServo"); // Using your configuration name
// Using a configuration name
NextServo armServo = new NextServo("armServo");
```

</TabItem>
Expand Down
6 changes: 4 additions & 2 deletions src/content/docs/hardware/miscellaneous/husky-lens.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ Anything else not wrapped is accessible through `camera`.
<TabItem label="Kotlin">

```kotlin
val huskyLens = NextHuskyLens("huskyLens") // Using your configuration name
// Using your configuration name
val huskyLens = NextHuskyLens("huskyLens")
```

</TabItem>
<TabItem label="Java">

```java
NextHuskyLens huskyLens = new NextHuskyLens("huskyLens"); // Using your configuration name
// Using your configuration name
NextHuskyLens huskyLens = new NextHuskyLens("huskyLens");
```

</TabItem>
Expand Down
6 changes: 4 additions & 2 deletions src/content/docs/hardware/miscellaneous/limelights.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ Any data that is not wrapped can be accessed through `camera`.
<TabItem label="Kotlin">

```kotlin
val limelight = NextLimelight("limelight") // Using your configuration name
// Using your configuration name
val limelight = NextLimelight("limelight")
```

</TabItem>
<TabItem label="Java">

```java
NextLimelight limelight = new NextLimelight("limelight"); // Using your configuration name
// Using your configuration name
NextLimelight limelight = new NextLimelight("limelight");
```

</TabItem>
Expand Down
12 changes: 8 additions & 4 deletions src/content/docs/hardware/miscellaneous/rgb-indicator.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ It extends [`NextServo`](/hardware/actuators/servos/), so everything from that c
<TabItem label="Kotlin">

```kotlin
val indicator = NextRGBIndicator(RobotController.controlHub, 0) // By Lynx Module and port, recommended
// By Lynx Module and port, recommended
val indicator = NextRGBIndicator(RobotController.controlHub, 0)

val indicator = NextRGBIndicator("LED") // Using your configuration name
// Using your configuration name
val indicator = NextRGBIndicator("LED")
```

</TabItem>
<TabItem label="Java">

```java
NextRGBIndicator indicator = new NextRGBIndicator(RobotController.getControlHub(), 0); // By Lynx Module and port, recommended
// By Lynx Module and port, recommended
NextRGBIndicator indicator = new NextRGBIndicator(RobotController.getControlHub(), 0);

NextRGBIndicator indicator = new NextRGBIndicator("LED"); // Using your configuration name
// Using your configuration name
NextRGBIndicator indicator = new NextRGBIndicator("LED");
```

</TabItem>
Expand Down
Loading
Loading