SERVO
servo.cpp@0:400439bce842, 2019-07-03 (annotated)
- Committer:
- firstsignupoftheweek
- Date:
- Wed Jul 03 09:51:18 2019 +0000
- Revision:
- 0:400439bce842
SERVO;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
firstsignupoftheweek | 0:400439bce842 | 1 | |
firstsignupoftheweek | 0:400439bce842 | 2 | //cpp file van servo class, alle functies worden hier uitgevoerd |
firstsignupoftheweek | 0:400439bce842 | 3 | //de servos hebben een effectieve 110 graden om te gebruiken, |
firstsignupoftheweek | 0:400439bce842 | 4 | //hierdoor hebben we de servos zo geprogrammeerd dat ze maar 90 graden hoeven te gebruiken, |
firstsignupoftheweek | 0:400439bce842 | 5 | //in plaats van 180 graden |
firstsignupoftheweek | 0:400439bce842 | 6 | //de servos moeten tegen elkaar in draaien om niet te verplaatsen |
firstsignupoftheweek | 0:400439bce842 | 7 | //2 servos staan dus altijd in de "90 graden" positie en de andere in de "0 graden" positie |
firstsignupoftheweek | 0:400439bce842 | 8 | //als we ze draaien worden ze precies andersom gedraaid |
firstsignupoftheweek | 0:400439bce842 | 9 | |
firstsignupoftheweek | 0:400439bce842 | 10 | |
firstsignupoftheweek | 0:400439bce842 | 11 | #include "mbed.h" |
firstsignupoftheweek | 0:400439bce842 | 12 | #include "servo.h" //include de header file waar de functies zijn gedeclareerd |
firstsignupoftheweek | 0:400439bce842 | 13 | |
firstsignupoftheweek | 0:400439bce842 | 14 | Servo::Servo(int tempcenteroffset, int tempninetyoffset, char tempdirection, PinName pin) : _pwm(pin){ //bind de pin aan een pwm pin |
firstsignupoftheweek | 0:400439bce842 | 15 | centeroffset = tempcenteroffset; //sla de offset 0 graden op |
firstsignupoftheweek | 0:400439bce842 | 16 | ninetyoffset = tempninetyoffset; //sla de offset van 90 graden op |
firstsignupoftheweek | 0:400439bce842 | 17 | direction = tempdirection; //sla op welke richting ze moeten draaien |
firstsignupoftheweek | 0:400439bce842 | 18 | _pwm.period_ms(20); //zet de period |
firstsignupoftheweek | 0:400439bce842 | 19 | } |
firstsignupoftheweek | 0:400439bce842 | 20 | |
firstsignupoftheweek | 0:400439bce842 | 21 | void Servo::servoCenter(){ //de servo op "0" graden draaien |
firstsignupoftheweek | 0:400439bce842 | 22 | if(direction == 'R'){ //moet de servo rechtsom draaien |
firstsignupoftheweek | 0:400439bce842 | 23 | _pwm.pulsewidth_us(ZERO+centeroffset); //zet de servo naar 0 + offset graden |
firstsignupoftheweek | 0:400439bce842 | 24 | } |
firstsignupoftheweek | 0:400439bce842 | 25 | if(direction == 'L'){ //moet de servo linksom draaien |
firstsignupoftheweek | 0:400439bce842 | 26 | _pwm.pulsewidth_us(NINETY+centeroffset); //zet de servo naar 90 + offset graden |
firstsignupoftheweek | 0:400439bce842 | 27 | } |
firstsignupoftheweek | 0:400439bce842 | 28 | } |
firstsignupoftheweek | 0:400439bce842 | 29 | |
firstsignupoftheweek | 0:400439bce842 | 30 | void Servo::turnRight(){ //de servo naar 90 graden draaien |
firstsignupoftheweek | 0:400439bce842 | 31 | if(direction == 'R'){ //moet de servo rechtsom draaien |
firstsignupoftheweek | 0:400439bce842 | 32 | _pwm.pulsewidth_us(NINETY+ninetyoffset); //zet de servo naar de 90 + offset graden |
firstsignupoftheweek | 0:400439bce842 | 33 | } |
firstsignupoftheweek | 0:400439bce842 | 34 | if(direction == 'L'){ //moet de servo linksom draaien |
firstsignupoftheweek | 0:400439bce842 | 35 | _pwm.pulsewidth_us(ZERO+ninetyoffset); //zet de servo naar 0 + offset graden |
firstsignupoftheweek | 0:400439bce842 | 36 | } |
firstsignupoftheweek | 0:400439bce842 | 37 | } |