new cppm example
This commit is contained in:
@@ -1,23 +1,39 @@
|
|||||||
/*
|
/*
|
||||||
This code is provided under the BSD license.
|
Example code is placed under the BSD license.
|
||||||
|
Written by Team Dark Water (team@darkwater.io) - based on original by Emlid
|
||||||
Copyright (c) 2014, Emlid Limited. All rights reserved.
|
Copyright (c) 2014, Emlid Limited. All rights reserved.
|
||||||
Written by Mikhail Avkhimenia (mikhail.avkhimenia@emlid.com)
|
Written by Mikhail Avkhimenia (mikhail.avkhimenia@emlid.com)
|
||||||
twitter.com/emlidtech || www.emlid.com || info@emlid.com
|
twitter.com/emlidtech || www.emlid.com || info@emlid.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
Application: PPM to PWM decoder for Raspberry Pi with Navio.
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
* Neither the name of the Emlid Limited nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this software
|
||||||
|
without specific prior written permission.
|
||||||
|
|
||||||
Requres pigpio library, please install it first - http://abyz.co.uk/rpi/pigpio/
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
To run this app navigate to the directory containing it and run following commands:
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
make
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
sudo ./PPM
|
DISCLAIMED. IN NO EVENT SHALL EMLID LIMITED BE LIABLE FOR ANY
|
||||||
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pigpio.h>
|
#include <pigpio.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <darkwater/gpio.h>
|
#include "darkwater/DWESCAPE.h"
|
||||||
#include "darkwater/PCA9685.h"
|
|
||||||
#include "darkwater/Util.h"
|
#include "darkwater/Util.h"
|
||||||
|
|
||||||
//================================ Options =====================================
|
//================================ Options =====================================
|
||||||
@@ -31,7 +47,9 @@ bool verboseOutputEnabled = true; // Output channels values to console
|
|||||||
|
|
||||||
//============================ Objects & data ==================================
|
//============================ Objects & data ==================================
|
||||||
|
|
||||||
PCA9685 *pwm;
|
DWESCAPE *dw;
|
||||||
|
DW_SERVO *servos[6];
|
||||||
|
|
||||||
float channels[8];
|
float channels[8];
|
||||||
|
|
||||||
//============================== PPM decoder ===================================
|
//============================== PPM decoder ===================================
|
||||||
@@ -51,7 +69,7 @@ void ppmOnEdge(int gpio, int level, uint32_t tick)
|
|||||||
|
|
||||||
// RC output
|
// RC output
|
||||||
for (int i = 0; i < ppmChannelsNumber; i++)
|
for (int i = 0; i < ppmChannelsNumber; i++)
|
||||||
pwm->setPWMuS(i + 3, channels[i]); // 1st Navio RC output is 3
|
servos[i]->setPWMuS( channels[i] );
|
||||||
|
|
||||||
// Console output
|
// Console output
|
||||||
if (verboseOutputEnabled) {
|
if (verboseOutputEnabled) {
|
||||||
@@ -68,33 +86,26 @@ void ppmOnEdge(int gpio, int level, uint32_t tick)
|
|||||||
|
|
||||||
//================================== Main ======================================
|
//================================== Main ======================================
|
||||||
|
|
||||||
using namespace Navio;
|
using namespace DarkWater;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
static const uint8_t outputEnablePin = RPI_GPIO_27;
|
|
||||||
|
|
||||||
if (check_apm()) {
|
if (check_apm()) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pin pin(outputEnablePin);
|
dw = new DWESCAPE();
|
||||||
|
dw.initialize();
|
||||||
|
dw.setFrequency(servoFrequency);
|
||||||
|
|
||||||
if (pin.init()) {
|
servos[0] = dw.getServo(1);
|
||||||
pin.setMode(Pin::GpioModeOutput);
|
servos[1] = dw.getServo(2);
|
||||||
pin.write(0); /* drive Output Enable low */
|
servos[2] = dw.getServo(3);
|
||||||
} else {
|
servos[3] = dw.getServo(4);
|
||||||
fprintf(stderr, "Output Enable not set. Are you root?");
|
servos[4] = dw.getServo(5);
|
||||||
}
|
servos[5] = dw.getServo(6);
|
||||||
|
|
||||||
// Servo controller setup
|
|
||||||
|
|
||||||
pwm = new PCA9685();
|
|
||||||
pwm->initialize();
|
|
||||||
pwm->setFrequency(servoFrequency);
|
|
||||||
|
|
||||||
// GPIO setup
|
// GPIO setup
|
||||||
|
|
||||||
gpioCfgClock(samplingRate, PI_DEFAULT_CLK_PERIPHERAL, 0); /* last parameter is deprecated now */
|
gpioCfgClock(samplingRate, PI_DEFAULT_CLK_PERIPHERAL, 0); /* last parameter is deprecated now */
|
||||||
gpioInitialise();
|
gpioInitialise();
|
||||||
previousTick = gpioTick();
|
previousTick = gpioTick();
|
||||||
|
|||||||
Reference in New Issue
Block a user