Software um den RC-Empfänger auszulesen und bei L298 anzusteuern, noch nicht perfekt und auch nur geklaut und angepasst, aber läuft soweit auf dem Pi. Bei fragen dazu gerne E-Mail an mich.
/*
This code is provided under the BSD license.
Copyright (c) 2014, Emlid Limited. All rights reserved.
Written by Mikhail Avkhimenia (mikhail(dot)avkhimenia(at)emlid(dot)com)
twitter.com/emlidtech || www.emlid.com || info(at)emlid(dot)com
Application: PPM to PWM decoder for Raspberry Pi with Navio.
Requres pigpio library, please install it first - http://abyz.co.uk/rpi/pigpio/
To run this app navigate to the directory containing it and run following commands:
make
sudo ./PPM
Umgebaut zu Kanaldecoder und direkter asugabe auf einem L298 (zwei, da ich die jeweils
parallel geschsltet habe.
*/
#include <pigpio.h>
#include <stdio.h>
#include <unistd.h>
//================================ Options =====================================
unsigned int samplingRate = 1; // 1 microsecond (can be 1,2,4,5,10)
unsigned int ppmInputGpio1 = 3; // PPM input on Navio's 2.54 header
unsigned int ppmInputGpio2 = 4; // PPM input on Navio's 2.54 header
unsigned int ppmSyncLength = 10000; // Length of PPM sync pause
unsigned int ppmChannelsNumber = 1; // Number of channels packed in PPM
unsigned int servoFrequency = 50; // Servo control frequency
bool verboseOutputEnabled = true; // Output channels values to console
#define PWM1 25 //ENABLE Pin des ersten L298
#define INA1 23 // INA (oder IN1) des ersten L298
#define INB1 24 // INB (oder IN2) des ersten 298
#define PWM2 11 //ENABLE Pin des zweiten L298
#define INA2 9 // INA (oder IN1) des zweiten L298
#define INB2 10 // INB (oder IN2) des zweiten 298
static int RICHTUNG1 = 0; // (Drehrichtung des Motors Nr.1, 0=Vorwärts, 1=Rückwärts
static int RICHTUNG2 = 0; // (Drehrichtung des Motors Nr.1, 0=Vorwärts, 1=Rückwärts
//============================ Objects & data ==================================
//============================== PPM decoder ===================================
unsigned int previousTick1;
unsigned int previousTick2;
unsigned int deltaTime1;
unsigned int deltaTime2;
unsigned int forward = 0;
unsigned int backward =0;
unsigned int left = 0;
unsigned int right = 0;
static int servo1 = 0;
static int servo2 = 0;
static int channel1 = 0;
static int channel2 = 0;
void ppmOnEdge1(int gpio, int level, uint32_t tick)
{
deltaTime1 = tick - previousTick1;
previousTick1 = tick;
if (level == 0)
if (deltaTime1 >= ppmSyncLength) { // Sync
}
else {
channel1 = ((deltaTime1-1000)/1.8);
if (channel1 > 510) {
channel1 = 510;
}
if (channel1 <= 2) {
channel1 = 2;
}
if (channel1 > 255){
servo1 = (channel1 - 255);
RICHTUNG1 = 0;
}
if (channel1 < 255) {
servo1 = ((channel1-255)*(-1));
RICHTUNG1 = 1;
}
gpioPWM(PWM1, servo1);
gpioWrite(INA1, RICHTUNG1); // INA auf gewünschte Richtung stellen
gpioWrite(INB1, !RICHTUNG1); // INB auf gewünschte Richtung stellen
}
}
void ppmOnEdge2(int gpio, int level, uint32_t tick)
{
deltaTime2 = tick - previousTick2;
previousTick2 = tick;
if (level == 0)
if (deltaTime2 >= ppmSyncLength) { // Sync
}
else {
channel2 = ((deltaTime2-1000)/1.8);
if (channel2 > 510) {
channel2 = 510;
}
if (channel2 <= 2) {
channel2 = 2;
}
if (channel2 > 255){
servo2 = (channel2 - 255);
RICHTUNG2 = 0;
}
if (channel2 < 255) {
servo2 = ((channel2-255)*(-1));
RICHTUNG2 = 1;
}
gpioPWM(PWM2, servo2);
gpioWrite(INA2, RICHTUNG2); // INA auf gewünschte Richtung stellen
gpioWrite(INB2, !RICHTUNG2); // INB auf gewünschte Richtung stellen
}
}
//=================================Andere Funktionen ==========================
/*
int servo1umrechnen() {
servo1 = (channel1-1000);
}
int servo2umrechnen() {
}
*/
//================================== Main ======================================
int main(int argc, char *argv[])
{
// GPIO setup
if (gpioInitialise()<0) return 1;
//gpioSetPWMfrequency(PWM1, servoFrequency);
//gpioCfgClock(samplingRate, PI_DEFAULT_CLK_PERIPHERAL, PI_DEFAULT_CLK_SOURCE);
gpioInitialise();
previousTick1 = gpioTick();
previousTick2 = gpioTick();
gpioSetAlertFunc(ppmInputGpio1, ppmOnEdge1);
gpioSetAlertFunc(ppmInputGpio2, ppmOnEdge2);
gpioSetMode(PWM1, PI_OUTPUT);
gpioSetMode(INA1, PI_OUTPUT);
gpioSetMode(INB1, PI_OUTPUT);
//gpioPWM(PWM1, servo1);
// Infinite sleep - all action is now happening in ppmOnEdge() function
while(1)
sleep(10);
//printf("Servo1 %d, Richtung1 %d Servo2 %d Richtung2 %d, Channel1 %d, Channel2 %d\n",servo1,RICHTUNG1,servo2,RICHTUNG2,channel1,channel2);
return 0;
}







