diff --git a/CopterController/DSM2.cpp b/CopterController/DSM2.cpp index e00824d..4899ea7 100644 --- a/CopterController/DSM2.cpp +++ b/CopterController/DSM2.cpp @@ -1,63 +1,34 @@ #include "DSM2.h" +#include #include "wiringSerial.h" -#include +#define VALUE_MASK 0x3FF -DSM2::DSM2( char* device, int mode ) +DSM2::DSM2( int mode ) { - - fd = serialOpen( device, 115200 ); - if( mode != 1024 && mode != 2048 ) mode = 1024; - if( mode == 1024 ) - { - valueSize = 10; - valueMask = 0x3FF; - - } - else - { - valueSize = 11; - valueMask = 0x7FF; - } + std::cout << "opening serial port..." << std::flush; + fd = serialOpen( "/dev/ttyAMA0", 115200 ); + std::cout << "SUCCESS " << fd << std::endl; + std::cout << "flushing serial..." << std::flush; + serialFlush(fd); + std::cout << "SUCCESS" << std::endl; } -bool DSM2::ready() -{ - if( serialDataAvail( fd ) >= 16 ) return true; - return false; -} - -void DSM2::update( bool block ) +void DSM2::update() { int i = 0; - if( block ) - { - while( !ready() ); - } - else if( !ready() ) return; - - for( i = 0; i < 8; i++ ) readNext(); - return; -} - -void DSM2::readNext() -{ - int channel, value, raw; - raw = ( serialGetchar( fd ) << 8 ) + serialGetchar( fd ); - - if( lastReadChan == chanBeforeFl ) - { - frameLoss = raw << 1 >> 1; - lastReadChan = -1; - return; - } - - channel = (raw & 0x7FFF) >> valueSize; - value = raw & valueMask; - values[ channel ] = value; - - lastReadChan = channel; + if( serialDataAvail(fd) < 16 ) return; + + for( i = 0; i < 8; i++ ) + data[ i ] = ( (int)(serialGetchar(fd)) << 8 ) + serialGetchar(fd); + + *(values + 0) = data[7] & VALUE_MASK; //Throttle + *(values + 1) = data[1] & VALUE_MASK; //Aileron + *(values + 2) = data[3] & VALUE_MASK; //Elevator + *(values + 3) = data[5] & VALUE_MASK; //Rudder + *(values + 4) = data[4] & VALUE_MASK; //Gear + *(values + 5) = data[2] & VALUE_MASK; //Aux1 return; } diff --git a/CopterController/DSM2.h b/CopterController/DSM2.h index 6a7120c..ef91bbf 100644 --- a/CopterController/DSM2.h +++ b/CopterController/DSM2.h @@ -1,24 +1,18 @@ #ifndef DSM2_H #define DSM2_H -#define chanBeforeFl -1 - -class DSM2 { +class DSM2 +{ public: - DSM2( char* device = "/dev/ttyAMA0", int mode = 1024 ); - - bool ready(); - void update( bool block = false ); - void readNext(); + DSM2( int mode = 1024 ); - int* values; - int frameLoss; + void update(); + int values[7]; private: - int lastReadChan; - - int fd; // file descriptor for serial bus - int valueSize; // number of bits for value part of frame + int fd; int valueMask; + char thisByte, lastByte; + int data[7]; }; #endif \ No newline at end of file diff --git a/CopterController/DSM2tester.cpp b/CopterController/DSM2tester.cpp index c2a7420..deae46d 100644 --- a/CopterController/DSM2tester.cpp +++ b/CopterController/DSM2tester.cpp @@ -1,21 +1,15 @@ +#include #include "DSM2.h" using namespace std; -int main( int argc, char* argv[] ) +int main(int argc, char const *argv[]) { - DSM2 dsm(); - + DSM2 dsm; while( true ) { - cout << "Thro" << dsm.values[0] << - "Aile" << dsm.values[1] << - "Elev" << dsm.values[2] << - "Rudd" << dsm.values[3] << - "Gear" << dsm.values[4] << - "Aux1" << dsm.values[5] << - "FL" << dsm.frameLoss << endl; - - dsm.update( true ); + dsm.update(); + cout << "THRO " << dsm.values[0] << "\tAILE " << dsm.values[1] << "\tELEV " << dsm.values[2] << "\tRUDD " << dsm.values[3] << "\tGEAR " << dsm.values[4] << "\tAUX1 " << dsm.values[5] << endl; } + return 0; } \ No newline at end of file diff --git a/CopterController/Makefile b/CopterController/Makefile index 02fc862..47db43d 100644 --- a/CopterController/Makefile +++ b/CopterController/Makefile @@ -1,4 +1,4 @@ -all: PID.o I2Cdev.o MPU6050.o PCA9685.o DSM2.o main v2main PCA9685tester echoServerAdvanced +all: PID.o I2Cdev.o MPU6050.o PCA9685.o DSM2.o PID.o PCA_HDRS = PCA9685.h PCA9685_Addresses.h MPU_HDRS = helper_3dmath.h I2Cdev.h MPU6050_6Axis_MotionApps20.h MPU6050.h @@ -11,11 +11,13 @@ CXXFLAGS = -DDMP_FIFO_RATE=9 -Wall -lwiringPi I2Cdev.o MPU6050.o PCA9685.o PID.o: $(HDRS) PCA9685tester.o echoServerAdvanced.o main.o: $(HDRS) -# version 2 stuff v2Parser.o: v2Parser.h helper_3dmath.h -DSM2.o: $(DSM_HDRS) PID.o: $(PID_HDRS) +DSM2.o DSM2tester.o: $(DSM_HDRS) +DSM2tester: DSM2tester.o DSM2.o + $(CXX) $^ -lwiringPi -o $@ + v2main.o: v2Parser.h $(PCA_HDRS) $(MPU_HDRS) $(PID_HDRS) v2main: v2main.o v2Parser.o PCA9685.o PID.o I2Cdev.o MPU6050.o DSM2.o $(CXX) $^ -lwiringPi -o $@ @@ -32,5 +34,9 @@ PCA9685tester: PCA9685.o PCA9685tester.o echoServerAdvanced: echoServerAdvanced.o PCA9685.o $(CXX) $^ -lwiringPi -o $@ +SatelliteReceiver.o SatelliteReceiverTest.o: SatelliteReceiver.h +SatelliteReceiverTest: SatelliteReceiver.o SatelliteReceiverTest.o + $(CXX) $^ -lwiringPi -o $@ + clean: rm I2Cdev.o MPU6050.o MPU6050dmp.o MPU6050dmp_tester.o MPU6050dmp_tester PID.o main.o main PCA9685tester \ No newline at end of file diff --git a/CopterController/README.md b/CopterController/README.md index 9be4eb9..3772723 100644 --- a/CopterController/README.md +++ b/CopterController/README.md @@ -1,8 +1,2 @@ Copter Controller === -Notes: ---- --DSM2 class does not work! ---DSM2.cpp ---DSM2.h ---DSM2tester.cpp \ No newline at end of file diff --git a/CopterController/v2DSM2.cpp b/CopterController/v2DSM2.cpp deleted file mode 100644 index 1c21a40..0000000 --- a/CopterController/v2DSM2.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "v2DSM2.h" - -#include -#include "wiringSerial.h" - -#define VALUE_MASK 0x3FF - -v2DSM2::v2DSM2( int mode ) -{ - std::cout << "opening serial port..." << std::flush; - fd = serialOpen( "/dev/ttyAMA0", 115200 ); - std::cout << "SUCCESS " << fd << std::endl; - std::cout << "flushing serial..." << std::flush; - serialFlush(fd); - std::cout << "SUCCESS" << std::endl; -} - -void v2DSM2::update() -{ - int i = 0; - - if( serialDataAvail(fd) < 16 ) return; - - for( i = 0; i < 8; i++ ) - data[ i ] = ( (int)(serialGetchar(fd)) << 8 ) + serialGetchar(fd); - - *(values + 0) = data[7] & VALUE_MASK; //Throttle - *(values + 1) = data[1] & VALUE_MASK; //Aileron - *(values + 2) = data[3] & VALUE_MASK; //Elevator - *(values + 3) = data[5] & VALUE_MASK; //Rudder - *(values + 4) = data[4] & VALUE_MASK; //Gear - *(values + 5) = data[2] & VALUE_MASK; //Aux1 - return; -} diff --git a/CopterController/v2DSM2.h b/CopterController/v2DSM2.h deleted file mode 100644 index dff6534..0000000 --- a/CopterController/v2DSM2.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef V2DSM2_H -#define V2DSM2_H - -class v2DSM2 -{ -public: - v2DSM2( int mode = 1024 ); - - void update(); - int values[7]; -private: - int fd; - int valueMask; - char thisByte, lastByte; - int data[7]; -}; - -#endif \ No newline at end of file diff --git a/CopterController/v2DSM2tester.cpp b/CopterController/v2DSM2tester.cpp deleted file mode 100644 index 0ac2fc5..0000000 --- a/CopterController/v2DSM2tester.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "v2DSM2.h" - -using namespace std; - -int main(int argc, char const *argv[]) -{ - v2DSM2 dsm; - while( true ) - { - dsm.update(); - cout << "THRO " << dsm.values[0] << "\tAILE " << dsm.values[1] << "\tELEV " << dsm.values[2] << "\tRUDD " << dsm.values[3] << "\tGEAR " << dsm.values[4] << "\tAUX1 " << dsm.values[5] << endl; - } - return 0; -} \ No newline at end of file diff --git a/README.md b/README.md index a357685..6ccfcbd 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ RasPi ===== +###Notes: +**DO NOT** run setup.sh, it doesn't work \ No newline at end of file diff --git a/setup.sh b/setup.sh index af953f0..1eac5e2 100644 --- a/setup.sh +++ b/setup.sh @@ -53,7 +53,7 @@ iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT # save these settings sh -c "iptables-save > /etc/iptables.ipv4.nat" -# modify /etc/network/interfaces +# modify /etc/network/interfaces (again) cat "up iptables-restore < /etc/iptables.ipv4.nat" >> /etc/network/interfaces # update hostapd