Code for the first milestone of Project Biorobotics. Make 2 motors turn with a speed indicated by the Pod-meters
Dependencies: FastPWM HIDScope MODSERIAL mbed
Diff: main.cpp
- Revision:
- 5:9827fabbc692
- Parent:
- 4:c73ced5d5754
--- a/main.cpp Tue Sep 25 14:02:15 2018 +0000 +++ b/main.cpp Thu Nov 01 08:52:14 2018 +0000 @@ -4,17 +4,28 @@ #include "HIDScope.h" +/* +Hallo! + +Het is tijd om de demo mode met behulp van potmeters te laten draaien :) +Zorg ervoor dat de potmeters met de draadjes aan de juiste poorten op de MBed zijn gekoppeld. +Het zijn de twee helemaal links onderin. + +Veel succes ermee en wees voorzichtig! +*/ + AnalogIn potmeter1(PTC10); AnalogIn potmeter2(PTC11); MODSERIAL pc(USBTX, USBRX); + //D4 is a digital input for the microcontroller, so should be an digitalOut -//from the K64F. It will tell the motor shiel to let Motor1 turn clockwise -//of count clockwise (CW of CCW). D4 for motor 2 +//from the K64F. It will tell the motor shield to let Motor1 turn clockwise +//or counter clockwise (CW of CCW). D7 for motor 2 DigitalOut directionM1(D4); DigitalOut directionM2(D7); //D5 is a PWM input for the motor controller and determines the PWM signal -//that the motor controller gives to Motor 1. Higher PWM, higer average voltage. -// D6 for motor 2 +//that the motor controller gives to Motor 1. Higher PWM, higher average voltage. +//D6 for motor 2 FastPWM motor1_pwm(D5); FastPWM motor2_pwm(D6); @@ -42,8 +53,8 @@ potwaarde1 = potmeter1.read(); // Lees de potwaardes uit. Tussen 0 en 1 potwaarde2 = potmeter2.read(); - U1 = potwaarde1*2 -1; // Scale van -1 tot 1 ipv. 0 tot 1 - U2 = potwaarde2*2 -1; + U1 = potwaarde1 -0.5; // Scale van -0.5 tot 0.5 ipv. 0 tot 1 + U2 = potwaarde2 -0.5; // Gebruik de absolute waarde van de scaled U waardes als input voor de motor. // Negatieve waardes kunnen niet naar de motor gestuurd worden. @@ -55,5 +66,4 @@ wait(0.002f); } - } \ No newline at end of file