add comments that explain what this commandgroups do
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / commands / MoveDefenseArm.java
CommitLineData
9b93bff0
CZ
1package org.usfirst.frc.team3501.robot.commands;
2
3import org.usfirst.frc.team3501.robot.Constants;
4
c5f13b9e 5import edu.wpi.first.wpilibj.command.CommandGroup;
9b93bff0
CZ
6
7/**
1c006b82
CZ
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
9b93bff0 14 */
6d20dad3 15public class MoveDefenseArm extends CommandGroup {
9b93bff0
CZ
16
17 double horizontalLimit, height;
18
d3fd4be0
CZ
19 public static final double ARM_SPEED = 0.6;
20
6d20dad3 21 public MoveDefenseArm(double horizontalLimit, double height) {
9b93bff0
CZ
22 this.horizontalLimit = horizontalLimit;
23 this.height = height;
d3fd4be0
CZ
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()));
9b93bff0
CZ
29 }
30
c5f13b9e 31 protected double calculateTargetArmAngle() {
9b93bff0
CZ
32 double armAngle;
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;
c5f13b9e
CZ
40 return armAngle;
41 }
9b93bff0 42
c5f13b9e 43 protected double calculateTargetHandAngle() {
9b93bff0
CZ
44 double handAngle;
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);
c5f13b9e 52 return handAngle;
9b93bff0
CZ
53 }
54
9b93bff0
CZ
55 public double square(double num) {
56 return num * num;
57 }
9b93bff0 58}