Ironcup Mar 2020

Dependencies:   mbed mbed-rtos MotionSensor EthernetInterface

Revision:
0:88faaa1afb83
Child:
8:a1067fcde341
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Protocol/receiver.h	Mon Apr 11 05:20:40 2016 +0000
@@ -0,0 +1,56 @@
+/*
+Copyright 2016 Erik Perillo <erik.perillo@gmail.com>
+
+This file is part of piranha-ptc.
+
+This is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+#ifndef __PIRANHA_RCV_PROTOCOL_H__
+#define __PIRANHA_RCV_PROTOCOL_H__
+
+#include "protocol.h"
+#include "mbed.h"
+
+
+/**
+ Reads serial and converts a string of (one or two) bytes into an unsigned int.
+ Least-significant bytes must come first.
+ Assumes big-endian representation of numbers on architecture.
+*/
+uint16_t read(Serial& serial);
+
+/**
+ Converts unsigned int into float following unit-normalization rules.
+*/
+float un_scale(uint16_t value, float min, float max);
+
+/**
+ Applies un_scale to value read on serial. 
+*/
+float get_param(Serial& serial, float min, float max);
+
+/**
+ Gets all 4 pid parameters from serial stream.
+*/
+void get_pid_params(Serial& serial, float* kp, float* ki, float* kd, float* n);
+
+//macros just to make life easier
+#define get_pid_param(serial) get_param(serial, PID_PARAMS_MIN, PID_PARAMS_MAX)
+#define get_gnd_speed(serial) get_param(serial, GND_SPEED_MIN, GND_SPEED_MAX)
+#define get_ang_ref(serial) get_param(serial, ANG_REF_MIN, ANG_REF_MAX)
+
+#endif
+