complete motor

Dependencies:   BufferedSerial motor_sn7544

Committer:
Jeonghoon
Date:
Thu Nov 21 11:39:20 2019 +0000
Revision:
13:3ac8d2472417
Parent:
7:13dd93a0efe8
complete motor

Who changed what in which revision?

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