mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[examples] Add Field2d to RamseteController example (#3371)
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
#include <frc/TimedRobot.h>
|
||||
#include <frc/XboxController.h>
|
||||
#include <frc/controller/RamseteController.h>
|
||||
#include <frc/smartdashboard/Field2d.h>
|
||||
#include <frc/smartdashboard/SmartDashboard.h>
|
||||
#include <frc/trajectory/TrajectoryGenerator.h>
|
||||
#include <frc2/Timer.h>
|
||||
|
||||
@@ -17,14 +19,23 @@ class Robot : public frc::TimedRobot {
|
||||
// Start the timer.
|
||||
m_timer.Start();
|
||||
|
||||
// Send Field2d to SmartDashboard.
|
||||
frc::SmartDashboard::PutData(&m_field);
|
||||
|
||||
// Reset the drivetrain's odometry to the starting pose of the trajectory.
|
||||
m_drive.ResetOdometry(m_trajectory.InitialPose());
|
||||
|
||||
// Send our generated trajectory to Field2d.
|
||||
m_field.GetObject("traj")->SetTrajectory(m_trajectory);
|
||||
}
|
||||
|
||||
void AutonomousPeriodic() override {
|
||||
// Update odometry.
|
||||
m_drive.UpdateOdometry();
|
||||
|
||||
// Update robot position on Field2d.
|
||||
m_field.SetRobotPose(m_drive.GetPose());
|
||||
|
||||
if (m_timer.Get() < m_trajectory.TotalTime()) {
|
||||
// Get the desired pose from the trajectory.
|
||||
auto desiredPose = m_trajectory.Sample(m_timer.Get());
|
||||
@@ -79,6 +90,9 @@ class Robot : public frc::TimedRobot {
|
||||
|
||||
// The timer to use during the autonomous period.
|
||||
frc2::Timer m_timer;
|
||||
|
||||
// Create Field2d for robot and trajectory visualizations.
|
||||
frc::Field2d m_field;
|
||||
};
|
||||
|
||||
#ifndef RUNNING_FRC_TESTS
|
||||
|
||||
Reference in New Issue
Block a user