1 package org
.usfirst
.frc
.team3501
.robot
.commands
;
3 import org
.usfirst
.frc
.team3501
.robot
.Constants
;
5 import edu
.wpi
.first
.wpilibj
.command
.CommandGroup
;
8 * Given input target x and y positions of the tip of the defense arm apparatus:
9 * first, calculates what the angle of the arm and hand corresponding to the
10 * given x-y coordinate is
11 * next, with speed of arm set to a constant, determine what the speed of hand
12 * should be if proportional to speed of arm (with the ratio equal to the ratio
13 * between arm angle to be adjusted and hand angle to be adjusted
15 public class MoveDefenseArm
extends CommandGroup
{
17 double horizontalLimit
, height
;
19 public static final double ARM_SPEED
= 0.6;
21 public MoveDefenseArm(double horizontalLimit
, double height
) {
22 this.horizontalLimit
= horizontalLimit
;
24 double targetArmAngle
= calculateTargetArmAngle();
25 double targetHandAngle
= calculateTargetHandAngle();
26 double handSpeed
= ARM_SPEED
* targetHandAngle
/ targetArmAngle
;
27 addParallel(new SetArmToAngle(ARM_SPEED
, calculateTargetArmAngle()));
28 addParallel(new SetHandToAngle(handSpeed
, calculateTargetHandAngle()));
31 protected double calculateTargetArmAngle() {
33 armAngle
= square(horizontalLimit
) + square(height
)
34 + square(Constants
.DefenseArm
.ARM_LENGTH
)
35 - square(Constants
.DefenseArm
.HAND_LENGTH
);
36 armAngle
/= 2 * Math
.sqrt(square(horizontalLimit
) + square(height
))
37 * Constants
.DefenseArm
.ARM_LENGTH
;
38 armAngle
= Math
.acos(armAngle
);
39 armAngle
= Math
.atan(height
/ horizontalLimit
) - armAngle
;
43 protected double calculateTargetHandAngle() {
45 handAngle
= square(horizontalLimit
) + square(height
)
46 + square(Constants
.DefenseArm
.HAND_LENGTH
)
47 - square(Constants
.DefenseArm
.ARM_LENGTH
);
48 handAngle
/= 2 * Math
.sqrt(square(horizontalLimit
) + square(height
))
49 * Constants
.DefenseArm
.HAND_LENGTH
;
50 handAngle
= Math
.acos(handAngle
);
51 handAngle
= handAngle
+ 90 - Math
.atan(horizontalLimit
/ height
);
55 public double square(double num
) {