Skip to content
Snippets Groups Projects
Commit 3578bb22 authored by Lukas Friedrichsen's avatar Lukas Friedrichsen
Browse files

tidiing up...

parent a1e0a21e
Branches
No related tags found
No related merge requests found
Showing
with 59 additions and 150 deletions
// LeonardoMixer.cpp // LeonardoMixer.cpp
// TODO License // Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// Lukas Friedrichsen, Philipp Stenkamp, 2017-1-6 // License: Modified BSD-License
// //
// Realtime RC mixer for Arduino-devices
//
// 2017-01-06
#include <Arduino.h> #include <Arduino.h>
#include "RC.h" #include "RC.h"
...@@ -32,20 +36,17 @@ nRtTask *nRtTasks[] = { &readRawSerial, &readSpektrum, &mix, NULL }; ...@@ -32,20 +36,17 @@ nRtTask *nRtTasks[] = { &readRawSerial, &readSpektrum, &mix, NULL };
void mix_Function (void) void mix_Function (void)
{ {
//Serial.println("MIX");
mixer.mix(); mixer.mix();
} }
void readSpektrum_Function (void) void readSpektrum_Function (void)
{ {
//Serial.println("SPEKTRUM");
spektrum.dataReceive(); spektrum.dataReceive();
spektrum.getData(); spektrum.getData();
} }
void readRawSerial_Function (void) void readRawSerial_Function (void)
{ {
//Serial.println("RAW_SERIAL");
serial.dataReceive(); serial.dataReceive();
serial.getData(); serial.getData();
} }
...@@ -75,9 +76,6 @@ void printLCD_Function () ...@@ -75,9 +76,6 @@ void printLCD_Function ()
void send_Function (void) void send_Function (void)
{ {
//Serial.println("SEND");
//printDebug();
msp.SerialEncode(); msp.SerialEncode();
} }
...@@ -117,7 +115,7 @@ void setup() ...@@ -117,7 +115,7 @@ void setup()
lcd.begin(2, 8); lcd.begin(2, 8);
while(Serial1.available()){ while(Serial1.available()){
Serial1.read(); //gibt es eine bessere möglichkeit () Serial1.read();
} }
} }
......
// Mixer.cpp // Mixer.cpp
// TODO License // Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// Philipp Stenkamp, 2016-11-7 // License: Modified BSD-License
// //
// Very basic implementation of an RC mixer. // Very basic implementation of an RC mixer.
// Mixing can be activated remotely via one of the input channels // Mixing can be activated remotely via one of the input channels
//
// 2016-11-07
#include "Mixer.h" #include "Mixer.h"
#include "Arduino.h" #include "Arduino.h"
......
// Mixer.h // Mixer.h
// TODO License // Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// Philipp Stenkamp, 2016-11-7 // License: Modified BSD-License
//
// 2016-11-07
#ifndef Mixer_h #ifndef Mixer_h
#define Mixer_h #define Mixer_h
......
// MultiWiiSerial.cpp // MultiWiiSerial.cpp
// TODO License // Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// Philipp Stenkamp, 2016-11-7 // License: Modified BSD-License
// //
// Implementation of the MultiWii Serial Protocol for Arduino // Implementation of the MultiWii Serial Protocol for Arduino
// http://www.multiwii.com/wiki/index.php?title=Multiwii_Serial_Protocol // http://www.multiwii.com/wiki/index.php?title=Multiwii_Serial_Protocol
//
// 2016-11-07
#include "MultiWiiSerial.h" #include "MultiWiiSerial.h"
#include "Arduino.h" #include "Arduino.h"
......
#include "MultiWiiSerial.h"
#include "Arduino.h"
#include "RC.h"
/*
* The general format of an MSP message is:
* <preamble>,<direction>,<size>,<command>,<data>,<crc>
* preamble = the ASCII characters '$M'
* direction = the ASCII character '<' if to the MWC or '>' if from the MWC
* size = number of data bytes, binary. Can be zero as in the case of a data request to the MWC
* command = message_id as per the table below
* data = as per the table below. UINT16 values are LSB first.
* crc = XOR of <size>, <command> and each data byte into a zero'ed sum
*/
MultiWiiSerial::MultiWiiSerial(rcSource *source) {
_source = source;
}
/* Needed if a reference to an HardwareSerial object is given, needs some logic to decide which type of Serial Object needs to be initialized
void MultiWiiSerial::init(Serial_ *msp_Serial){
_Serial = msp_Serial;
_Serial->begin(115200);
}
*/
void MultiWiiSerial::init(HardwareSerial *msp_Serial){
_Serial = msp_Serial;
_Serial->begin(115200);
}
void MultiWiiSerial::SerialEncode()
{
uint8_t header[] = {'$', 'M', '<', MSP_FRAME_SIZE, 200}; //Fixed header for sending raw RC Data
uint8_t crc = 0;
crc ^= MSP_FRAME_SIZE;
crc ^= 200;
//crc = makeCRC(crc, header + 3, 2); // checksum starts from len field
_Serial->write(header, 5);
for(uint8_t i = 0; i < MSP_FRAME_SIZE/2; i++){
crc = crc ^ uint8_t(_source->data[i]%256);
_Serial->write(uint8_t(_source->data[i]%256));
crc = crc ^ uint8_t(_source->data[i]/256);
_Serial->write(uint8_t(_source->data[i]/256));
}
_Serial->write(crc);
}
void MultiWiiSerial::dataReceive(){
while (_Serial->available() >= MSP_FRAME_SIZE) //DANGEROUS, runtime dependent on serial input, NO REALTIME AT ALL!!
{
_Serial->readBytes(frame, MSP_FRAME_SIZE);
}
}
uint16_t MultiWiiSerial::readRawRC(uint8_t chan){
return frame[chan];
}
// MultiWiiSerial.h // MultiWiiSerial.h
// TODO License // Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// Philipp Stenkamp, 2016-11-7 // License: Modified BSD-License
// //
// Implementation of the MultiWii Serial Protocol for Arduino // 2016-11-07
// http://www.multiwii.com/wiki/index.php?title=Multiwii_Serial_Protocol
#ifndef MultiWiiSerial_h #ifndef MultiWiiSerial_h
#define MultiWiiSerial_h #define MultiWiiSerial_h
......
/*
* Implementation of the MultiWii Serial Protocol
* http://www.multiwii.com/wiki/index.php?title=Multiwii_Serial_Protocol
*
*
*
* Philipp Stenkamp - 7-11-2016
*/
#ifndef MultiWiiSerial_h
#define MultiWiiSerial_h
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include "Arduino.h"
#include "RC.h"
#define MSP_MAX_SUPPORTED_CHANNEL_COUNT 8
#define MSP_FRAME_SIZE 8*2
class MultiWiiSerial {
public:
MultiWiiSerial(rcSource *source);
//void init(Serial_ *msp_Serial);
void init(HardwareSerial *msp_Serial);
void dataReceive();
uint16_t readRawRC(uint8_t chan);
void SerialEncode();
private:
HardwareSerial *_Serial;
rcSource *_source;
uint8_t channelCount;
uint16_t rxRefreshRate;
uint8_t frame[MSP_FRAME_SIZE];
uint16_t channelData[MSP_MAX_SUPPORTED_CHANNEL_COUNT]; // shouldn't be channelCount to prevent going out of bounds in case of misconfiguration
};
#endif
// RC.h // RC.h
// TODO License // Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// Philipp Stenkamp, 2016-11-7 // License: Modified BSD-License
// //
// Provides an array of channel data for a given number of channels. // 2016-11-07
// Can be signed with a timestamp to indicate timeliness of the data.
#ifndef RC_h #ifndef RC_h
#define RC_h #define RC_h
......
// RawSerial.h // RawSerial.h
// TODO License // Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// Philipp Stenkamp, 2016-11-7 // License: Modified BSD-License
// //
// Implementation of a simple serial data protocol. // Implementation of a simple serial data protocol.
// Primarily meant for use with our OpenCV Android Circle Tracking App // Primarily meant for use with our OpenCV Android Circle Tracking App
// TODO Project Name // Visual Based Landing System
// TODO url // https://gitlab.cvh-server.de/lf.ps/vbls/Visual-Based-Landing-System/
//
// 2016-11-07
#include "RawSerial.h" #include "RawSerial.h"
#include "Arduino.h" #include "Arduino.h"
......
// RawSerial.h // RawSerial.h
// TODO License // Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// Philipp Stenkamp, 2016-11-7 // License: Modified BSD-License
// //
// Implementation of a simple serial RC data protocol. // 2016-11-07
// Primarily meant for use with our OpenCV Android Circle Tracking App
// TODO Project Name
// TODO url
#ifndef RawSerial_h #ifndef RawSerial_h
#define RawSerial_h #define RawSerial_h
......
// Scheduler.cpp // Scheduler.cpp
// TODO License // Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// Lukas Friedrichsen, 2016-12- // License: Modified BSD-License
// //
// Implementation of a cooperative multitasking based scheduler for Arduino-devices
//
// 2017-02-10
#include "Scheduler.h" #include "Scheduler.h"
...@@ -244,7 +248,6 @@ void Scheduler::schedule (void) { ...@@ -244,7 +248,6 @@ void Scheduler::schedule (void) {
if (rtTasks) { if (rtTasks) {
unsigned long timerDiff = getTaskTimerDiff(rtTasks->listElement); unsigned long timerDiff = getTaskTimerDiff(rtTasks->listElement);
unsigned long cycleTime = getTaskCycleTime((rtTask *) rtTasks->listElement); unsigned long cycleTime = getTaskCycleTime((rtTask *) rtTasks->listElement);
//debugger->println("cycle-time: "+(String)cycleTime+" timer-diff: "+(String)timerDiff+" micros: "+(String)micros());
if (timerDiff >= cycleTime) { if (timerDiff >= cycleTime) {
if (((timerDiff-cycleTime)*100/cycleTime) > OVERLOAD_THRESHOLD_PERCENT) { if (((timerDiff-cycleTime)*100/cycleTime) > OVERLOAD_THRESHOLD_PERCENT) {
overloadCounter++; overloadCounter++;
......
// Scheduler.h // Scheduler.h
// TODO License // Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// Lukas Friedrichsen, 2016-12- // License: Modified BSD-License
// //
// 2017-02-10
#ifndef Scheduler_h #ifndef Scheduler_h
#define Scheduler_h #define Scheduler_h
......
// Spektrum.cpp // Spektrum.cpp
// TODO License // Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// Philipp Stenkamp, 2016-11-7 // License: Modified BSD-License
// //
// Implementation of the Spektrum Satellite Serial Protocol for Arduino // Implementation of the Spektrum Satellite Serial Protocol for Arduino
// based on the Spektrum Remote Receiver Interfacing Specification // based on the Spektrum Remote Receiver Interfacing Specification
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
// //
// In the style of Cleanflight // In the style of Cleanflight
// https://github.com/cleanflight/cleanflight/tree/master/src/main/rx // https://github.com/cleanflight/cleanflight/tree/master/src/main/rx
// 2016-11-07
#include "Spektrum.h" #include "Spektrum.h"
......
// Spektrum.h // Spektrum.h
// TODO License // Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// Philipp Stenkamp, 2016-11-7 // License: Modified BSD-License
// //
// Implementation of the Spektrum Remote Receiver Interfacing Specification // 2016-11-07
// https://www.spektrumrc.com/ProdInfo/Files/Remote%20Receiver%20Interfacing%20Rev%20A.pdf
//
// Partly based on and heavily influenced by Cleanflight
// https://github.com/cleanflight/cleanflight/tree/master/src/main/rx
#ifndef Spektrum_h #ifndef Spektrum_h
#define Spektrum_h #define Spektrum_h
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment