
Werkt
Dependencies: Encoder HIDScope MODSERIAL QEI mbed
Fork of Inverse_kinematics_PIDController by
Diff: main.cpp
- Revision:
- 3:56cbed6caacc
- Parent:
- 2:ffd0553701d3
- Child:
- 4:f36406c9e42f
--- a/main.cpp Wed Oct 17 10:12:06 2018 +0000 +++ b/main.cpp Wed Oct 17 13:36:47 2018 +0000 @@ -7,35 +7,35 @@ DigitalOut directionpin2(D8); MODSERIAL pc(USBTX, USBRX); -volatile bool emg0; -volatile bool emg1; -volatile bool emg2; -volatile bool y_direction; +volatile bool emg0Bool = false; +volatile bool emg1Bool = false; +volatile bool emg2Bool = false; +volatile bool y_direction = true; volatile double x_position = 0; volatile double y_position = 0; volatile double motor1_angle; volatile double motor2_angle; -volatile double direction; +volatile int direction; const float length = 0.300; //length in m (placeholder) const int C1 = 3; //motor 1 gear ratio (placeholder) const int C2 = 3; //motor 2 gear ratio -void xDirection(double &motor1_angle, double &motor2_angle) { - //direction of the motion - if (emg0 && !emg1) { - directionpin1 = true; - directionpin2 = true; - direction = 1; - } - else if (!emg0 && emg1) { - directionpin1 = false; - directionpin2 = false; - direction = -1; - } +void xDirection() { + //direction of the motion + if (emg0Bool && !emg1Bool) { + directionpin1 = true; + directionpin2 = true; + direction = 1; + } + else if (!emg0Bool && emg1Bool) { + directionpin1 = false; + directionpin2 = false; + direction = -1; + } - if (emg0 || emg1){ + if (emg0Bool || emg1Bool){ //calculating the motion x_position = x_position + direction; motor1_angle = pow(sin( x_position ), -1) / length; @@ -44,8 +44,8 @@ } } -void yDirection (int &motor2_angle) { - if (emg2) { +void yDirection () { + if (emg2Bool) { //direction of the motion if (y_direction) { directionpin2 = true; @@ -65,8 +65,12 @@ int main() { pc.printf(" ** program reset **\n\r"); while (true) { - xDirection(motor1_angle, motor2_angle); - yDirection(motor2_angle); + if (button) { + y_direction = !y_direction; + } + + xDirection(); + yDirection(); pc.printf("motor1 angle: %i\n\r", motor1_angle); pc.printf("motor2 angle: %i\n\r\n", motor2_angle);