mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
[examples] Synchronize C++ and Java Mechanism2d examples (#3589)
- Synchronize dimensions - Make both joints different colors for clarity
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
#include <frc/smartdashboard/Mechanism2d.h>
|
||||
#include <frc/smartdashboard/MechanismLigament2d.h>
|
||||
#include <frc/smartdashboard/SmartDashboard.h>
|
||||
#include <frc/util/Color.h>
|
||||
#include <frc/util/Color8Bit.h>
|
||||
#include <units/angle.h>
|
||||
|
||||
/**
|
||||
@@ -57,13 +59,14 @@ class Robot : public frc::TimedRobot {
|
||||
// the main mechanism object
|
||||
frc::Mechanism2d m_mech{3, 3};
|
||||
// the mechanism root node
|
||||
frc::MechanismRoot2d* m_root = m_mech.GetRoot("climber", 3, 3);
|
||||
frc::MechanismRoot2d* m_root = m_mech.GetRoot("climber", 2, 0);
|
||||
// MechanismLigament2d objects represent each "section"/"stage" of the
|
||||
// mechanism, and are based off the root node or another ligament object
|
||||
frc::MechanismLigament2d* m_elevator =
|
||||
m_root->Append<frc::MechanismLigament2d>("elevator", 1, 90_deg);
|
||||
frc::MechanismLigament2d* m_wrist =
|
||||
m_elevator->Append<frc::MechanismLigament2d>("wrist", 0.5, 90_deg);
|
||||
m_elevator->Append<frc::MechanismLigament2d>(
|
||||
"wrist", 0.5, 90_deg, 6, frc::Color8Bit{frc::Color::kPurple});
|
||||
};
|
||||
|
||||
#ifndef RUNNING_FRC_TESTS
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
"foldername":"Mechanism2d",
|
||||
"gradlebase":"cpp",
|
||||
"description":"An example usage of Mechanism2d to display mechanism states on a dashboard.",
|
||||
"tags":[],
|
||||
"tags":["Mechanism2d"],
|
||||
"commandversion": 2
|
||||
},
|
||||
{
|
||||
|
||||
@@ -211,7 +211,7 @@
|
||||
},
|
||||
{"name": "Mechanism2d",
|
||||
"description": "An example usage of Mechanism2d to display mechanism states on a dashboard.",
|
||||
"tags": [],
|
||||
"tags": ["Mechanism2d"],
|
||||
"foldername": "mechanism2d",
|
||||
"gradlebase": "java",
|
||||
"mainclass": "Main",
|
||||
|
||||
@@ -13,6 +13,8 @@ import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
import edu.wpi.first.wpilibj.util.Color;
|
||||
import edu.wpi.first.wpilibj.util.Color8Bit;
|
||||
|
||||
/**
|
||||
* This sample program shows how to use Mechanism2d - a visual representation of arms, elevators,
|
||||
@@ -39,14 +41,16 @@ public class Robot extends TimedRobot {
|
||||
m_elevatorEncoder.setDistancePerPulse(kMetersPerPulse);
|
||||
|
||||
// the main mechanism object
|
||||
Mechanism2d mech = new Mechanism2d(200, 200);
|
||||
Mechanism2d mech = new Mechanism2d(3, 3);
|
||||
// the mechanism root node
|
||||
MechanismRoot2d root = mech.getRoot("climber", 80, 100);
|
||||
MechanismRoot2d root = mech.getRoot("climber", 2, 0);
|
||||
|
||||
// MechanismLigament2d objects represent each "section"/"stage" of the mechanism, and are based
|
||||
// off the root node or another ligament object
|
||||
m_elevator = root.append(new MechanismLigament2d("elevator", 10, 90));
|
||||
m_wrist = m_elevator.append(new MechanismLigament2d("wrist", 6, 90));
|
||||
m_elevator = root.append(new MechanismLigament2d("elevator", kElevatorMinimumLength, 90));
|
||||
m_wrist =
|
||||
m_elevator.append(
|
||||
new MechanismLigament2d("wrist", 0.5, 90, 6, new Color8Bit(Color.kPurple)));
|
||||
|
||||
// post the mechanism to the dashboard
|
||||
SmartDashboard.putData("Mech2d", mech);
|
||||
|
||||
Reference in New Issue
Block a user