-
Notifications
You must be signed in to change notification settings - Fork 0
Fixes/princeton #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes/princeton #23
Changes from all commits
38a3d5b
ab6549d
89b32c6
a26cbf1
b1d6c12
f4badca
ca8bf50
3ee54bd
c89d6b1
037c033
e26986e
083ce40
0a8c1c4
a76d1fd
23efaf1
830a75b
950b6f3
77b2175
2d5d196
458d3af
a726c28
e032a90
06d03b5
08bbd47
fe4406c
346aeea
f798087
162a946
0340e64
543ec57
a08751a
8fe373a
92f59ef
51a1475
4f0dee7
72fed28
056068f
4d104f3
38df1ee
f80676f
e94e38c
a9d5d16
c4f72cd
02af6d2
d3e2f38
2a24e85
a01cc69
90e34d8
e86e93f
3d559eb
dd4dc4e
c679bed
5a6eb32
ec66791
16d3b8a
716d710
3a24a58
b7c5e13
ae5adde
662ce27
14341b3
2cfbca9
18642d0
5c5bf95
bae168b
44c7c1c
576021c
5510e45
03bf1cf
6096d18
36afb95
226f6de
5a1d3bf
12de51d
4be56ec
6b708f7
ca005a3
5aa979b
75ae2ec
ab33db5
b6c94fe
c8e3de6
8bab878
b1ba987
a871339
08cbbf0
da39782
765555d
7810e00
b3b1594
e7cf4b6
dea32f1
9aeec2f
6c694a9
749ac4d
4c9a09f
e794f08
1b56539
d1b012c
f67f409
0f4ec52
a335343
fe571bf
d002d5f
e5009ac
2bbe6eb
a907c65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| #include "commands/arm/ArmTeleopCommand.h" | ||
boxofrox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include "subsystems/arm/arm.h" | ||
|
|
||
| #include <frc/XboxController.h> | ||
|
|
||
| #include <cmath> | ||
|
|
||
| #define JOYSTICK_DEADZONE 0.1 | ||
| #define DEADZONE(input) ((std::abs(input) < JOYSTICK_DEADZONE) ? 0.0 : input) | ||
|
|
||
| const double k_maxPointSpeed = 0.005; | ||
| const double k_maxPointRotSpeed = (2.0 * M_PI / 10.0) * 0.02; // radians per second in 20ms. | ||
| const double k_maxWristRotSpeed = (2.0 * M_PI / 2.0) * 0.02; | ||
| const double k_maxGripSpeed = 0.1; | ||
|
Comment on lines
+11
to
+14
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should go in the Constants.h file
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. review :)
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These constants aren't meant to be shared with an other parts of the program. I had concerns that someone might be inclined to reuse them for another purpose and have cause to change them. I'm inclined to leave this for the competition as it's tested, and change it after.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok. is there a possibility after competition to rename it to be |
||
|
|
||
| ArmTeleopCommand::ArmTeleopCommand(ArmSubsystem* arm, frc::XboxController* operatorController) { | ||
| c_operatorController = operatorController; | ||
| c_arm = arm; | ||
|
|
||
| AddRequirements(c_arm); | ||
| } | ||
|
|
||
| void ArmTeleopCommand::Initialize() { | ||
| // Update target to current point so arm doesn't move unexpectedly. | ||
| m_target = c_arm->getGripPoint(); | ||
| c_arm->moveToPoint(m_target); | ||
| } | ||
|
|
||
| void ArmTeleopCommand::Execute() { | ||
| { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we add a comment here and at the end of this block saying something like: |
||
| Vector offsetLX; | ||
| Vector offsetLY; | ||
| Vector offsetRY; | ||
| double gripMag = std::sqrt(std::pow(m_target.x,2)+std::pow(m_target.y,2)); | ||
| double gripDir = std::atan2(m_target.x, m_target.y); // 0 deg == y axis | ||
|
|
||
| // Rotate turret. Speed of rotation is reduced the further the arm reaches. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we move the second comment to line 44? |
||
| double leftX = c_operatorController->GetLeftX(); | ||
| // Square input to improve fidelity. | ||
| leftX = DEADZONE(leftX); | ||
| leftX = std::copysign(std::clamp(leftX * leftX, -1.0, 1.0), leftX); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we use
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's doesn't matter to me. Either way gets the point across. I'd like to think the c++ compiler is smart enough to convert a function call into a single equivalent multiplication, but I couldn't say for sure. |
||
| if (0.0 != leftX) { | ||
| // (+) leftX should move turret clockwise. | ||
| double dir = gripDir + (leftX * k_maxPointRotSpeed) / std::max(gripMag,1.0); | ||
| Point point1( | ||
| gripMag * std::sin(dir), | ||
| gripMag * std::cos(dir), | ||
| m_target.z | ||
| ); | ||
| offsetLX = point1 - m_target; | ||
| } | ||
|
|
||
| // Extend/retract gripper from/to turret. | ||
| double leftY = -c_operatorController->GetLeftY(); /* Invert so + is forward */ | ||
| // Square input to improve fidelity. | ||
| leftY = DEADZONE(leftY); | ||
| leftY = std::copysign(std::clamp(leftY * leftY, -1.0, 1.0), leftY); | ||
| if (0.0 != leftY) { | ||
| // (+) leftY should move away from turret. | ||
| double mag = gripMag + (leftY * k_maxPointSpeed); | ||
| Point point1( | ||
| mag * std::sin(gripDir), | ||
| mag * std::cos(gripDir), | ||
| m_target.z | ||
| ); | ||
| offsetLY = point1 - m_target; | ||
| } | ||
|
|
||
| // Move gripper up or down. | ||
| double rightY = -c_operatorController->GetRightY(); /* Invert so + is up */ | ||
| // Square input to improve fidelity. | ||
| rightY = DEADZONE(rightY); | ||
| rightY = std::copysign(std::clamp(rightY * rightY, -1.0, 1.0), rightY); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we put |
||
| if (0.0 != rightY) { | ||
| // (+) rightY should move gripper up. | ||
| offsetRY = Vector(0.0, 0.0, rightY * k_maxPointSpeed); | ||
boxofrox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| m_target = m_target + offsetLX + offsetLY + offsetRY; | ||
|
|
||
| c_arm->moveToPoint(m_target); | ||
| } | ||
|
|
||
| // Rotate wrist clockwise or counterclockwise. | ||
| { | ||
| double leftTrigger = c_operatorController->GetLeftTriggerAxis(); | ||
| double rightTrigger = c_operatorController->GetRightTriggerAxis(); | ||
| double trigger = leftTrigger - rightTrigger; | ||
| // Square input to improve fidelity. | ||
| trigger = DEADZONE(trigger); | ||
| trigger = std::copysign(std::clamp(trigger * trigger, -1.0, 1.0), trigger); | ||
|
|
||
| // Use current angle as default so wrist doesn't move wildly upon enable. | ||
| double wristTargetAngle = c_arm->getWristRollAngle(); | ||
|
|
||
| if (0.0 != trigger) { | ||
| // (+) trigger should rotate wrist counter-clockwise, looking down forearm. | ||
| wristTargetAngle += trigger * k_maxWristRotSpeed; | ||
| } | ||
|
|
||
| // Move/hold wrist angle. | ||
| c_arm->setWristRollAngle(wristTargetAngle); | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we add
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is to mark the end of the block? Sure. If the comment isn't inline with the closing brace, then prefix the comment with |
||
|
|
||
| // Open and close gripper. | ||
| { | ||
| double bumper = | ||
| (c_operatorController->GetRightBumper() ? 1.0 : 0.0) | ||
| - (c_operatorController->GetLeftBumper() ? 1.0 : 0.0); | ||
|
|
||
| // Use current position as default so grip doesn't move wildly upon enable. | ||
| double gripTargetPos = c_arm->getGrip(); | ||
|
|
||
| if (0.0 != bumper) { | ||
| gripTargetPos += bumper * k_maxGripSpeed; | ||
| } | ||
|
|
||
| // Move/hold grip. | ||
| c_arm->setGrip(gripTargetPos); | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we add
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same answer as line 103 |
||
| } | ||
|
|
||
| void ArmTeleopCommand::End(bool interrupted) { | ||
| // Update target to current point so arm stops. | ||
| // Cannot stop motors because shoulder will backdrive and fall. | ||
| m_target = c_arm->getGripPoint(); | ||
| } | ||
|
|
||
| bool ArmTeleopCommand::IsFinished() { | ||
| return false; // dont end because then we wont be able to drive | ||
boxofrox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| void ArmTeleopCommand::resetTarget(){ | ||
| m_target = c_arm->getGripPoint(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #include "commands/arm/MoveToIntake.h" | ||
boxofrox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #include "subsystems/arm/motionPath.h" | ||
| #include "subsystems/arm/arm.h" | ||
| #include "subsystems/arm/armPose.h" | ||
|
|
||
| MoveToIntakeCommand::MoveToIntakeCommand(ArmSubsystem * arm, Point currentPoint) { | ||
| m_arm = arm; | ||
boxofrox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| m_currentPoint = currentPoint; | ||
|
|
||
| AddRequirements(m_arm); | ||
| } | ||
|
|
||
| void MoveToIntakeCommand::Initialize() { | ||
| m_finalTarget = m_arm->m_pointIntake; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we use a |
||
| Point currentPoint = m_arm->getGripPoint(); | ||
|
|
||
| m_path.emplace(std::move(m_arm->getPathTo(currentPoint, m_finalTarget))); | ||
| m_target = m_path->getNextPoint(); | ||
| } | ||
|
|
||
| void MoveToIntakeCommand::Execute() { | ||
| if(m_finalTarget.isNear(m_target) && m_arm->isNearPoint(m_target)) { | ||
| return; | ||
| } else if (m_arm->isNearPoint(m_target)) { | ||
| m_target = m_path->getNextPoint(); | ||
| } | ||
|
|
||
| if (!m_arm->isPointSafe(m_target)) { | ||
| return; | ||
| } | ||
|
|
||
| ArmPose calculatedIKPose = m_arm->calcIKJointPoses(m_target); | ||
| } | ||
|
|
||
| void MoveToIntakeCommand::End(bool isInterrupted) { | ||
| //heeyaw | ||
boxofrox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| bool MoveToIntakeCommand::IsFinished() { | ||
| return !m_arm->isPointSafe(m_target) | ||
| || (m_finalTarget.isNear(m_target) && m_arm->isNearPoint(m_target)); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.