servo test
This commit is contained in:
@@ -3,7 +3,7 @@ DW = ../../darkwater
|
|||||||
INCLUDES = -I ../..
|
INCLUDES = -I ../..
|
||||||
|
|
||||||
all:
|
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:
|
clean:
|
||||||
rm Servo
|
rm Servo
|
||||||
|
|||||||
@@ -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_MIN 1.250 /*mS*/
|
||||||
#define SERVO_MAX 1.750 /*mS*/
|
#define SERVO_MAX 1.750 /*mS*/
|
||||||
|
|
||||||
#include <darkwater/gpio.h>
|
#include "darkwater/DW640.h"
|
||||||
#include "darkwater/PCA9685.h"
|
|
||||||
#include "darkwater/Util.h"
|
#include "darkwater/Util.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
using namespace DarkWater;
|
using namespace DarkWater;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
static const uint8_t outputEnablePin = RPI_GPIO_27;
|
|
||||||
|
|
||||||
if (check_apm()) {
|
if (check_apm()) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pin pin(outputEnablePin);
|
DW640 dw;
|
||||||
|
dw.initialize();
|
||||||
if (pin.init()) {
|
dw.setFrequency(50);
|
||||||
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);
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
pwm.setPWMmS(NAVIO_RCOUTPUT_1, SERVO_MIN);
|
dw.setServoPWMmS(1, SERVO_MIN);
|
||||||
sleep(1);
|
usleep(1000000);
|
||||||
pwm.setPWMmS(NAVIO_RCOUTPUT_1, SERVO_MAX);
|
dw.setServoPWMmS(1, SERVO_MAX);
|
||||||
sleep(1);
|
usleep(1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user