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

tidiing up...

parent a1e0a21e
No related branches found
No related tags found
No related merge requests found
Showing
with 59 additions and 150 deletions
// LeonardoMixer.cpp
// TODO License
// Lukas Friedrichsen, Philipp Stenkamp, 2017-1-6
// Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// License: Modified BSD-License
//
// Realtime RC mixer for Arduino-devices
//
// 2017-01-06
#include <Arduino.h>
#include "RC.h"
......@@ -32,20 +36,17 @@ nRtTask *nRtTasks[] = { &readRawSerial, &readSpektrum, &mix, NULL };
void mix_Function (void)
{
//Serial.println("MIX");
mixer.mix();
}
void readSpektrum_Function (void)
{
//Serial.println("SPEKTRUM");
spektrum.dataReceive();
spektrum.getData();
}
void readRawSerial_Function (void)
{
//Serial.println("RAW_SERIAL");
serial.dataReceive();
serial.getData();
}
......@@ -75,9 +76,6 @@ void printLCD_Function ()
void send_Function (void)
{
//Serial.println("SEND");
//printDebug();
msp.SerialEncode();
}
......@@ -117,7 +115,7 @@ void setup()
lcd.begin(2, 8);
while(Serial1.available()){
Serial1.read(); //gibt es eine bessere möglichkeit ()
Serial1.read();
}
}
......
// Mixer.cpp
// TODO License
// Philipp Stenkamp, 2016-11-7
// Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// License: Modified BSD-License
//
// Very basic implementation of an RC mixer.
// Mixing can be activated remotely via one of the input channels
//
// 2016-11-07
#include "Mixer.h"
#include "Arduino.h"
......
// Mixer.h
// TODO License
// Philipp Stenkamp, 2016-11-7
// Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// License: Modified BSD-License
//
// 2016-11-07
#ifndef Mixer_h
#define Mixer_h
......
// MultiWiiSerial.cpp
// TODO License
// Philipp Stenkamp, 2016-11-7
// Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// License: Modified BSD-License
//
// Implementation of the MultiWii Serial Protocol for Arduino
// http://www.multiwii.com/wiki/index.php?title=Multiwii_Serial_Protocol
//
// 2016-11-07
#include "MultiWiiSerial.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
// TODO License
// Philipp Stenkamp, 2016-11-7
// Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// License: Modified BSD-License
//
// Implementation of the MultiWii Serial Protocol for Arduino
// http://www.multiwii.com/wiki/index.php?title=Multiwii_Serial_Protocol
// 2016-11-07
#ifndef 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
// TODO License
// Philipp Stenkamp, 2016-11-7
// Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// License: Modified BSD-License
//
// Provides an array of channel data for a given number of channels.
// Can be signed with a timestamp to indicate timeliness of the data.
// 2016-11-07
#ifndef RC_h
#define RC_h
......
// RawSerial.h
// TODO License
// Philipp Stenkamp, 2016-11-7
// Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// License: Modified BSD-License
//
// Implementation of a simple serial data protocol.
// Primarily meant for use with our OpenCV Android Circle Tracking App
// TODO Project Name
// TODO url
// Visual Based Landing System
// https://gitlab.cvh-server.de/lf.ps/vbls/Visual-Based-Landing-System/
//
// 2016-11-07
#include "RawSerial.h"
#include "Arduino.h"
......
// RawSerial.h
// TODO License
// Philipp Stenkamp, 2016-11-7
// Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// License: Modified BSD-License
//
// Implementation of a simple serial RC data protocol.
// Primarily meant for use with our OpenCV Android Circle Tracking App
// TODO Project Name
// TODO url
// 2016-11-07
#ifndef RawSerial_h
#define RawSerial_h
......
// Scheduler.cpp
// TODO License
// Lukas Friedrichsen, 2016-12-
// Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// License: Modified BSD-License
//
// Implementation of a cooperative multitasking based scheduler for Arduino-devices
//
// 2017-02-10
#include "Scheduler.h"
......@@ -244,7 +248,6 @@ void Scheduler::schedule (void) {
if (rtTasks) {
unsigned long timerDiff = getTaskTimerDiff(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)*100/cycleTime) > OVERLOAD_THRESHOLD_PERCENT) {
overloadCounter++;
......
// Scheduler.h
// TODO License
// Lukas Friedrichsen, 2016-12-
// Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// License: Modified BSD-License
//
// 2017-02-10
#ifndef Scheduler_h
#define Scheduler_h
......
// Spektrum.cpp
// TODO License
// Philipp Stenkamp, 2016-11-7
// Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// License: Modified BSD-License
//
// Implementation of the Spektrum Satellite Serial Protocol for Arduino
// based on the Spektrum Remote Receiver Interfacing Specification
......@@ -8,6 +8,7 @@
//
// In the style of Cleanflight
// https://github.com/cleanflight/cleanflight/tree/master/src/main/rx
// 2016-11-07
#include "Spektrum.h"
......
// Spektrum.h
// TODO License
// Philipp Stenkamp, 2016-11-7
// Copyright 2016, 2017 Lukas Friedrichsen, Philipp Stenkamp
// License: Modified BSD-License
//
// Implementation of the Spektrum Remote Receiver Interfacing Specification
// 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
// 2016-11-07
#ifndef 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