ros melodic library with custom message

Dependents:   Robot_team1_QEI_Douglas Robot_team1

Committer:
scarter1
Date:
Wed Oct 30 14:59:49 2019 +0000
Revision:
0:020db18a476d
melodic library;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
scarter1 0:020db18a476d 1 /*
scarter1 0:020db18a476d 2 * MbedHardware
scarter1 0:020db18a476d 3 *
scarter1 0:020db18a476d 4 * Created on: Aug 17, 2011
scarter1 0:020db18a476d 5 * Author: nucho
scarter1 0:020db18a476d 6 */
scarter1 0:020db18a476d 7
scarter1 0:020db18a476d 8 #ifndef ROS_MBED_HARDWARE_H_
scarter1 0:020db18a476d 9 #define ROS_MBED_HARDWARE_H_
scarter1 0:020db18a476d 10
scarter1 0:020db18a476d 11 #include "mbed.h"
scarter1 0:020db18a476d 12
scarter1 0:020db18a476d 13 #include "BufferedSerial.h"
scarter1 0:020db18a476d 14
scarter1 0:020db18a476d 15 class MbedHardware {
scarter1 0:020db18a476d 16 public:
scarter1 0:020db18a476d 17 MbedHardware(PinName tx, PinName rx, long baud = 57600)
scarter1 0:020db18a476d 18 :iostream(tx, rx){
scarter1 0:020db18a476d 19 baud_ = baud;
scarter1 0:020db18a476d 20 t.start();
scarter1 0:020db18a476d 21 }
scarter1 0:020db18a476d 22
scarter1 0:020db18a476d 23 MbedHardware()
scarter1 0:020db18a476d 24 :iostream(USBTX, USBRX) {
scarter1 0:020db18a476d 25 baud_ = 57600;
scarter1 0:020db18a476d 26 t.start();
scarter1 0:020db18a476d 27 }
scarter1 0:020db18a476d 28
scarter1 0:020db18a476d 29 void setBaud(long baud){
scarter1 0:020db18a476d 30 this->baud_= baud;
scarter1 0:020db18a476d 31 }
scarter1 0:020db18a476d 32
scarter1 0:020db18a476d 33 int getBaud(){return baud_;}
scarter1 0:020db18a476d 34
scarter1 0:020db18a476d 35 void init(){
scarter1 0:020db18a476d 36 iostream.baud(baud_);
scarter1 0:020db18a476d 37 }
scarter1 0:020db18a476d 38
scarter1 0:020db18a476d 39 int read(){
scarter1 0:020db18a476d 40 if (iostream.readable()) {
scarter1 0:020db18a476d 41 return iostream.getc();
scarter1 0:020db18a476d 42 } else {
scarter1 0:020db18a476d 43 return -1;
scarter1 0:020db18a476d 44 }
scarter1 0:020db18a476d 45 };
scarter1 0:020db18a476d 46 void write(uint8_t* data, int length) {
scarter1 0:020db18a476d 47 for (int i=0; i<length; i++)
scarter1 0:020db18a476d 48 iostream.putc(data[i]);
scarter1 0:020db18a476d 49 }
scarter1 0:020db18a476d 50
scarter1 0:020db18a476d 51 unsigned long time(){return t.read_ms();}
scarter1 0:020db18a476d 52
scarter1 0:020db18a476d 53 protected:
scarter1 0:020db18a476d 54 BufferedSerial iostream;
scarter1 0:020db18a476d 55 long baud_;
scarter1 0:020db18a476d 56 Timer t;
scarter1 0:020db18a476d 57 };
scarter1 0:020db18a476d 58
scarter1 0:020db18a476d 59
scarter1 0:020db18a476d 60 #endif /* ROS_MBED_HARDWARE_H_ */