servo test

This commit is contained in:
shrkey
2016-10-10 20:59:15 +01:00
parent dae54e4814
commit d1044b7aad
2 changed files with 10 additions and 38 deletions

View File

@@ -3,7 +3,7 @@ DW = ../../darkwater
INCLUDES = -I ../..
all:
$(CC) $(INCLUDES) Servo.cpp $(DW)/PCA9685.cpp $(DW)/I2Cdev.cpp $(DW)/gpio.cpp $(DW)/Util.cpp -o Servo
$(CC) $(INCLUDES) Servo.cpp $(DW)/DW640.cpp $(DW)/PCA9685.cpp $(DW)/I2Cdev.cpp $(DW)/gpio.cpp $(DW)/Util.cpp -o Servo
clean:
rm Servo

View File

@@ -1,56 +1,28 @@
/*
Provided to you by Emlid Ltd (c) 2014.
twitter.com/emlidtech || www.emlid.com || info@emlid.com
Example: Control servos connected to PCA9685 driver onboard of Navio shield for Raspberry Pi.
Connect servo to Navio's rc output and watch it work.
Output 1 on board is connected to PCA9685 channel 3, output 2 to channel 4 and so on.
To use full range of your servo correct SERVO_MIN and SERVO_MAX according to it's specification.
To run this example navigate to the directory containing it and run following commands:
make
./Servo
*/
#define NAVIO_RCOUTPUT_1 3
#define SERVO_MIN 1.250 /*mS*/
#define SERVO_MAX 1.750 /*mS*/
#include <darkwater/gpio.h>
#include "darkwater/PCA9685.h"
#include "darkwater/DW640.h"
#include "darkwater/Util.h"
#include <stdlib.h>
using namespace DarkWater;
int main()
{
static const uint8_t outputEnablePin = RPI_GPIO_27;
if (check_apm()) {
return 1;
}
Pin pin(outputEnablePin);
if (pin.init()) {
pin.setMode(Pin::GpioModeOutput);
pin.write(0); /* drive Output Enable low */
} else {
fprintf(stderr, "Output Enable not set. Are you root?\n");
return 1;
}
PCA9685 pwm;
pwm.initialize();
pwm.setFrequency(50);
DW640 dw;
dw.initialize();
dw.setFrequency(50);
while (true) {
pwm.setPWMmS(NAVIO_RCOUTPUT_1, SERVO_MIN);
sleep(1);
pwm.setPWMmS(NAVIO_RCOUTPUT_1, SERVO_MAX);
sleep(1);
dw.setServoPWMmS(1, SERVO_MIN);
usleep(1000000);
dw.setServoPWMmS(1, SERVO_MAX);
usleep(1000000);
}
return 0;