Skip to content

Commit

Permalink
Merge branch 'main' into trajopt-spline-initial-guess-wpilib
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Jan 3, 2025
2 parents e6363a4 + a33629c commit 81eec8a
Show file tree
Hide file tree
Showing 32 changed files with 308 additions and 211 deletions.
2 changes: 1 addition & 1 deletion docs/document-settings/robot-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ These values should be determined by consulting the motor's documentation.

!!! tip "Choosing a Motor Max Speed"

A reasonable choice of Motor Max Speed is ~80% of the free speed of the drive motor(s). Although your motors have more speed available, this headroom helps ensure that your robot is able to close any errors and return to the planned trajectory. Use the [Motor Calculator](#motor-calculator) to help select an appropriate value.
A reasonable choice of Motor Max Speed is ~80% of the free speed of the drive motor(s). Although your motors have more speed available, this headroom helps ensure that your robot is able to close any errors and return to the planned trajectory.

- **Motor Max Torque** $[N * m]$: The maximum torque applied by each drive motor

Expand Down
Binary file modified docs/media/field_options.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 modified docs/media/focus.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 modified docs/media/project_info.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 modified docs/media/project_not_saved.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 docs/media/samples-mini-waypoints.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 modified docs/media/samples.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 modified docs/media/sidebar.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 modified docs/media/view_options_panel.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 modified docs/media/waypoints.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 14 additions & 20 deletions docs/usage/saving.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Once trajectories are created by Choreo, they must be saved within your robot project.

Choreo has 2 different kinds of files: a .chor file which stores general configs for your project,
and multiple .traj files which store individual trajectories. Choreo generates and updates .traj files
and multiple .traj files which store individual path information. Each .traj file correlates to one path in Choreo. Choreo generates and updates .traj files
in the same directory (or folder) that your .chor file is stored in.

## Saving your .chor file
Expand Down Expand Up @@ -33,50 +33,44 @@ To access the sidebar, click the hamburger icon in the upper left corner.

General Info:

In the sidebar, there are four actions related to saving your project, along with your project's current save location.

In the sidebar, there are five actions related to saving your project, along with your project's current save location.
## Open Project

## Open File
This opens the system’s file select dialog to select the robot’s `.chor` file.

This opens the system’s file select dialog to select the robot’s `.chor` file. This .chor file should be under the folders `src/main/deploy/choreo`
in your robot project.
## Save Project/Save Project As

## Save File
This opens the system’s file save dialog to select where to save the robot’s `.chor` file.

This opens the system’s file save dialog to select where to save the robot’s `.chor` file. Choreo strongly recommends saving this file in your `deploy/choreo` folder within your project.
## New Project

## New File
Creates a new unsaved project.

Creates a new file in memory, essentially clearing all trajectories. If you have unsaved changes, Choreo will ask before clearing them.
## Export Diagnostic Report

## Export Trajectory

Exports the trajectory as a file individually to the path you select in the UI. This is not tied with the robot project structure, so you can place the trajectory file anywhere you like.

## Save All Trajectories

This saves all the trajectories into the folder structure described below.
This exports a .zip file with your project `.chor` and `.traj` files, as well as some logs. Choreo support may ask for this report when trying to help you.

## Project Details

If you have saved your choreo file correctly, you should see the following:

![Project Info](../media/project_info.png)

Below "Project saved at", you can see the directory in which the saved `.chor` file lives. You can also copy this path or open it in your system's file explorer.
Below "Project saved at", you can see the directory in which the project files live. You can also copy this path or open it in your system's file explorer.

!!! warning

If you get the below, it means you have not saved the file yet
If you get the below, it means you have not saved the file yet.

![Project not saved](../media/project_not_saved.png){: style="height:60px;"}

# Folder Structure Example

For C++ and Java teams:

- Choreo file lives at: `~/Development/FRC/Roboto/src/main/deploy/choreo/ChoreoProject.chor`
- Trajectories (`.traj`) live in: `~/Development/FRC/Roboto/src/main/deploy/choreo/...`
- Choreo file lives at: `~/Development/FRC/Robot/src/main/deploy/choreo/ChoreoProject.chor`
- Trajectories (`.traj`) live in: `~/Development/FRC/Robot/src/main/deploy/choreo/...`

For Python teams:

Expand Down
11 changes: 6 additions & 5 deletions docs/usage/view-options-panel.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ Split trajectories on stop points are shown in different colors. In other words,

### Field

Shows the field svg overlay.
Shows the field background layer.

### Grid

Shows the grid overlay
Shows a 1 meter grid layer.

### Trajectory

Expand All @@ -65,14 +65,15 @@ Shows the grid overlay
### Samples

![samples](../media/samples.png)
![Mini waypoints](../media/samples-mini-waypoints.png)

Shows a dot at every sample along the path, and mini waypoints at the locations of the waypoints that generated the trajectory.

### Waypoints

![waypoints](../media/waypoints.png)

### Obstacles

Shows the obstacles in the path.
Shows or hides the editable waypoints.

### Focus

Expand Down
3 changes: 2 additions & 1 deletion src-core/src/file_management/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ type DeployPath = Arc<Mutex<PathBuf>>;
type TrajectoryFileName = String;

mod diagnostics;
mod formatter;

pub mod formatter;
pub mod upgrader;

pub use diagnostics::{create_diagnostic_file, get_log_lines};
Expand Down
74 changes: 67 additions & 7 deletions src-core/src/spec/trajectory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use trajoptlib::{DifferentialTrajectorySample, SwerveTrajectorySample};

use super::{upgraders::upgrade_traj_file, Expr, SnapshottableType};

#[derive(Serialize, Deserialize, Clone, Copy, Debug)]
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
/// A waypoint parameter.
pub struct Waypoint<T: SnapshottableType> {
Expand Down Expand Up @@ -53,7 +53,7 @@ impl<T: SnapshottableType> Waypoint<T> {
}

/// A waypoint identifier.
#[derive(Serialize, Deserialize, Clone, Copy, Debug)]
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum WaypointID {
/// The first waypoint.
Expand Down Expand Up @@ -106,7 +106,7 @@ pub enum ConstraintScope {
}

/// A constraint on the robot's motion.
#[derive(Serialize, Deserialize, Clone, Copy, Debug)]
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
#[serde(tag = "type", content = "props")]
pub enum ConstraintData<T: SnapshottableType> {
/// A constraint on the maximum velocity.
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<T: SnapshottableType> ConstraintData<T> {
}

/// A constraint on the robot's motion and where it applies.
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
pub struct Constraint<T: SnapshottableType> {
/// The waypoint the constraint starts at.
pub from: WaypointID,
Expand All @@ -237,7 +237,7 @@ impl<T: SnapshottableType> Constraint<T> {
}

/// A constraint on the robot's motion and where it applies.
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
pub struct ConstraintIDX<T: SnapshottableType> {
/// The index of the waypoint the constraint starts at.
pub from: usize,
Expand All @@ -252,7 +252,7 @@ pub struct ConstraintIDX<T: SnapshottableType> {

/// A sample of the robot's state at a point in time during the trajectory.
#[allow(missing_docs)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum Sample {
/// A sample for a swerve drive.
Expand Down Expand Up @@ -363,7 +363,7 @@ pub enum DriveType {
}

/// The parameters used for generating a trajectory.
#[derive(Serialize, Deserialize, Clone, Debug)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Parameters<T: SnapshottableType> {
/// The waypoints the robot will pass through or use for initial guess.
Expand Down Expand Up @@ -441,6 +441,15 @@ impl TrajectoryFile {
let val = upgrade_traj_file(serde_json::from_str(content)?)?;
serde_json::from_value(val).map_err(Into::into)
}

pub fn up_to_date(&self) -> bool {
// Can't use is_some_and due to its move semantics.
if let Some(snap) = &self.snapshot {
snap == &self.params.snapshot()
} else {
false
}
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -482,3 +491,54 @@ pub enum PplibCommand {
commands: Vec<PplibCommand>,
},
}

#[cfg(test)]
mod tests {
use crate::spec::TRAJ_SCHEMA_VERSION;

use super::*;
fn test_trajectory() -> TrajectoryFile {
let parameters = Parameters::<Expr> {
waypoints: vec![Waypoint::<Expr> {
x: Expr::fill_in_value(0.0, "m"),
y: Expr::fill_in_value(0.0, "m"),
heading: Expr::fill_in_value(0.0, "rad"),
intervals: 20,
split: false,
fix_translation: false,
fix_heading: false,
override_intervals: false,
is_initial_guess: false,
}],
constraints: vec![],
target_dt: Expr::fill_in_value(0.05, "s"),
};
TrajectoryFile {
name: "Test".to_string(),
version: TRAJ_SCHEMA_VERSION,
snapshot: Some(parameters.snapshot()),
params: parameters,
trajectory: Trajectory {
sample_type: Some(DriveType::Swerve),
waypoints: Vec::new(),
samples: Vec::new(),
splits: Vec::new(),
},
events: Vec::new(),
}
}
#[test]
fn snapshot_equality() {
assert!(test_trajectory().up_to_date());
}

#[test]
fn snapshot_equality_through_serde() -> serde_json::Result<()> {
use crate::file_management::formatter;
let trajectory = test_trajectory();
let serde_trajectory = formatter::to_string_pretty(&trajectory)?;
let deser_trajectory = TrajectoryFile::from_content(serde_trajectory.as_str());
assert!(deser_trajectory.is_ok_and(|t| t.up_to_date()));
Ok(())
}
}
5 changes: 5 additions & 0 deletions src-tauri/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ pub async fn delete_trajectory(
debug_result!(file_management::delete_trajectory_file(&resources, trajectory).await);
}

#[tauri::command]
pub async fn trajectory_up_to_date(trajectory: TrajectoryFile) -> bool {
trajectory.up_to_date()
}

#[tauri::command]
pub async fn set_deploy_root(app_handle: tauri::AppHandle, dir: String) {
let resources = app_handle.state::<WritingResources>();
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/tauri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ pub fn run_tauri(project: Option<PathBuf>) {
open_project_dialog,
read_trajectory,
rename_trajectory,
trajectory_up_to_date,
set_deploy_root,
get_deploy_root,
requested_file,
Expand Down
Loading

0 comments on commit 81eec8a

Please sign in to comment.