PPM updates for 640

This commit is contained in:
shrkey
2016-10-17 17:06:36 +01:00
parent cc2b77b0ad
commit db2a71b85f
2 changed files with 50 additions and 33 deletions

View File

@@ -8,7 +8,7 @@ INCLUDES = -I ../.. -I$(PIGPIO_PATH)
all: all:
$(CC) $(INCLUDES) $(LIB) PPM.cpp $(DW)/PCA9685.cpp $(DW)/I2Cdev.cpp $(DW)/gpio.cpp $(DW)/Util.cpp -o PPM -lrt -lpthread -lpigpio $(CC) $(INCLUDES) $(LIB) PPM.cpp $(DW)/DW640.cpp $(DW)/PCA9685.cpp $(DW)/I2Cdev.cpp $(DW)/gpio.cpp $(DW)/Util.cpp -o PPM -lrt -lpthread -lpigpio
clean: clean:
rm PPM rm PPM

View File

@@ -1,38 +1,59 @@
/* /*
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/DW640.h"
#include "darkwater/PCA9685.h"
#include "darkwater/Util.h" #include "darkwater/Util.h"
#include <stdlib.h>
//================================ Options ===================================== //================================ Options =====================================
unsigned int samplingRate = 1; // 1 microsecond (can be 1,2,4,5,10) unsigned int samplingRate = 1; // 1 microsecond (can be 1,2,4,5,10)
unsigned int ppmInputGpio = 4; // PPM input on Navio's 2.54 header unsigned int ppmInputGpio = 4; // PPM input on Navio's 2.54 header
unsigned int ppmSyncLength = 4000; // Length of PPM sync pause unsigned int ppmSyncLength = 4000; // Length of PPM sync pause
unsigned int ppmChannelsNumber = 8; // Number of channels packed in PPM unsigned int ppmChannelsNumber = 6; // Number of channels packed in PPM
unsigned int servoFrequency = 50; // Servo control frequency unsigned int motorFrequency = 100; // Servo control frequency
bool verboseOutputEnabled = true; // Output channels values to console bool verboseOutputEnabled = true; // Output channels values to console
//============================ Objects & data ================================== //============================ Objects & data ==================================
PCA9685 *pwm; using namespace DarkWater;
float channels[8];
DW640 *dw;
DW_Motor *motors[6];
float channels[6];
//============================== PPM decoder =================================== //============================== PPM decoder ===================================
@@ -50,8 +71,13 @@ void ppmOnEdge(int gpio, int level, uint32_t tick)
currentChannel = 0; currentChannel = 0;
// 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 // Sanity checks for values
if( channels[i] > 2000 ) channels[i] = 2000;
if( channels[i] < 1000 ) channels[i] = 1000;
// Set motor speed
motors[i]->setMotorSpeed( channels[i] );
}
// Console output // Console output
if (verboseOutputEnabled) { if (verboseOutputEnabled) {
@@ -68,33 +94,24 @@ void ppmOnEdge(int gpio, int level, uint32_t tick)
//================================== Main ====================================== //================================== Main ======================================
using namespace Navio;
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(motorFrequency);
if (pin.init()) { motors[0] = dw->getMotor(1);
pin.setMode(Pin::GpioModeOutput); motors[1] = dw->getMotor(2);
pin.write(0); /* drive Output Enable low */ motors[2] = dw->getMotor(3);
} else { motors[3] = dw->getMotor(4);
fprintf(stderr, "Output Enable not set. Are you root?"); motors[4] = dw->getMotor(5);
} motors[5] = dw->getMotor(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();