[examples] Synchronize C++ and Java Mechanism2d examples (#3589)

- Synchronize dimensions
- Make both joints different colors for clarity
This commit is contained in:
sciencewhiz
2021-09-18 22:05:35 -07:00
committed by GitHub
parent a7fb831035
commit a446c25598
4 changed files with 15 additions and 8 deletions

View File

@@ -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",

View File

@@ -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);