TrekkingPhoenix / Mbed 2 deprecated TrekkingControllerV1-4_WinterChallenge20

Dependencies:   mbed mbed-rtos MotionSensor EthernetInterface

Protocol/receiver.h

Committer:
drelliak
Date:
2016-04-23
Revision:
8:a1067fcde341
Parent:
0:88faaa1afb83

File content as of revision 8:a1067fcde341:

/*
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);

/**
 Gets jogging velocity.
*/
void get_jog_vel(Serial& serial, float* period, float* ratio);

//macros just to make life easier
#define get_pid_param(serial) get_param(serial, PID_PARAMS_MIN, PID_PARAMS_MAX)
#define get_gnd_vel(serial) get_param(serial, GND_VEL_MIN, GND_VEL_MAX)
#define get_ang_ref(serial) get_param(serial, ANG_REF_MIN, ANG_REF_MAX)

#endif