-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoveArm.cpp
More file actions
52 lines (44 loc) · 1.1 KB
/
MoveArm.cpp
File metadata and controls
52 lines (44 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/** Moves the arm to the specified position
* @author Hans Johnson
* @date Sept. 2015
**/
#include "MoveArm.h"
/**
* Constructor - does not initalize the motor.
* @param Setpoint The pot value to move the arm to
**/
MoveArm::MoveArm(int Setpoint) : Command("MoveArm") {
setpoint = Setpoint+ARM_POT_OFFSET;
}
/**
* Initializes the motor pin
**/
void MoveArm::initialize() {
armMotor.attach(ARM_MOTOR_PIN);
}
/**
* Drives the MoveArm to the provided setpoint
**/
void MoveArm::execute() {
input = analogRead(POTPIN);
error = setpoint-input;
//current_time = millis();
//accum_error += error/(float)(current_time-prev_time);
output = Kp*(float)error + Kd*(float)(error-last_error);// Ki*(float)(accum_error) +
output = constrain(output, -500, 500);
armMotor.writeMicroseconds(1500+output);//+output);
last_error = error;
}
/**
* Finished when error is less than the threshold specified in MoveArm.h
**/
bool MoveArm::isFinished() {
return abs(error) < threshold;
}
/**
* Stops the MoveArm movement when Finished
**/
void MoveArm::end() {
armMotor.writeMicroseconds(1500);
armMotor.detach();
}