![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Script 15-10-2019
Dependencies: Servoaansturing mbed QEI HIDScope biquadFilter MODSERIAL FastPWM
main.cpp
- Committer:
- Rosalie
- Date:
- 2019-10-07
- Revision:
- 3:6ee0b20c23b0
- Parent:
- 2:aee655d11b6d
- Child:
- 4:6742476fadcf
File content as of revision 3:6ee0b20c23b0:
#include "mbed.h" #include "HIDScope.h" #include "QEI.h" #include "MODSERIAL.h" #include "BiQuad.h" #include "FastPWM.h" #include <math.h> //definieer objecten Serial pc(USBTX, USBRX); Ticker myControllerTicker1; Ticker myControllerTicker2; AnalogIn potMeter1(A0); AnalogIn potMeter2(A1); PwmOut motor1(D5); PwmOut motor2(D6); DigitalOut motor1_dir(D4); DigitalOut motor2_dir(D7); InterruptIn button1(D2); InterruptIn button2(D1); //richting wisselen van motor 1 void direction1(void) { motor1_dir=!motor1_dir; } //richting wisselen van motor 2 void direction2(void) { motor2_dir=!motor2_dir; } //snelheid motor 1 aansturen void motor1Controller( ) { // Determine reference (desired) fan speed double y1_des = potMeter1.read(); // Controller (calculate motor torque/pwm) if( y1_des > 1 ) y1_des = 1; // y1_des must be <= 1 if( y1_des < 0 ) y1_des = 0; // y1_des must be >= 0 double power1 = pow(y1_des, 2.0); // Inverse relation between input and output // Send to motor motor1.write( power1 ); pc.printf("power1: %.2f\t",power1); } //snelheid motor 2 aansturen void motor2Controller( ) { // Determine reference (desired) fan speed double y2_des = potMeter2.read(); // Controller (calculate motor torque/pwm) if( y2_des > 1 ) y2_des = 1; // y2_des must be <= 1 if( y2_des < 0 ) y2_des = 0; // y2_des must be >= 0 double power2 = pow(y2_des, 2.0); // Inverse relation between input and output // Send to motor motor2.write( power2 ); pc.printf("power2: %.2f\n\r",power2); } int main() { myControllerTicker1.attach(motor1Controller, 0.1 ); // Every 1/10 second myControllerTicker2.attach(motor2Controller, 0.1 ); // Every 1/10 second button1.mode(PullUp); button1.rise(direction1); button2.mode(PullUp); button2.rise(direction2); while( true ) { /* do nothing */ } return 0; }