Test to control motors
Dependencies: HIDScope_friso MODSERIAL QEI mbed
Diff: main.cpp
- Revision:
- 3:62e950f20604
- Parent:
- 2:8fb37a4587f1
- Child:
- 4:f6ca4f7793bd
diff -r 8fb37a4587f1 -r 62e950f20604 main.cpp --- a/main.cpp Mon Oct 24 08:25:58 2016 +0000 +++ b/main.cpp Mon Oct 24 08:36:05 2016 +0000 @@ -47,6 +47,8 @@ void controlmotor() { //set motor speed angleerror = referenceangle-angle; + if (angleerror < 0) motor1_direction = 1; + if (angleerror > 0) motor1_direction = 0; potmeter = potmeter1.read(); referencevelocity = potmeter*max_velocity; motor1_pwm.pulsewidth(referencevelocity/max_velocity*0.020); @@ -54,7 +56,7 @@ void calculateangle() { //calculate the angle of the axis based on counts if (counts == 0) angle = 0; - else angle = counts/countspr*2*pi; + else angle = -counts/countspr*2*pi; } void derivative() { //calculate velocity based on derivative