Shundo Kishi / Mbed 2 deprecated Hobby_Humanoid_controlor

Dependencies:   Adafruit-PWM-Servo-Driver MPU6050 RS300 mbed

Committer:
syundo0730
Date:
Tue Apr 02 04:19:09 2013 +0000
Revision:
17:60de3bfdc70b
Parent:
16:e65c192b7ecf
+realtime module(not move well)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
syundo0730 17:60de3bfdc70b 1
syundo0730 12:6cd135bf03bd 2 #include "SCI.h"
syundo0730 12:6cd135bf03bd 3
syundo0730 12:6cd135bf03bd 4 SCI::SCI(PinName tx, PinName rx)
syundo0730 12:6cd135bf03bd 5 {
syundo0730 12:6cd135bf03bd 6 serial = new Serial(tx, rx);
syundo0730 12:6cd135bf03bd 7 }
syundo0730 12:6cd135bf03bd 8
syundo0730 12:6cd135bf03bd 9 SCI::~SCI()
syundo0730 12:6cd135bf03bd 10 {
syundo0730 12:6cd135bf03bd 11 delete serial;
syundo0730 12:6cd135bf03bd 12 }
syundo0730 12:6cd135bf03bd 13
syundo0730 16:e65c192b7ecf 14 char SCI::getheader()
syundo0730 16:e65c192b7ecf 15 {
syundo0730 16:e65c192b7ecf 16 char comm = getc_nowait();
syundo0730 16:e65c192b7ecf 17 if (comm != 0x00) {
syundo0730 16:e65c192b7ecf 18 serial->putc(comm);
syundo0730 16:e65c192b7ecf 19 }
syundo0730 16:e65c192b7ecf 20 return comm;
syundo0730 16:e65c192b7ecf 21 }
syundo0730 16:e65c192b7ecf 22
syundo0730 13:711f74b2fa33 23 int SCI::getid()
syundo0730 12:6cd135bf03bd 24 {
syundo0730 13:711f74b2fa33 25 int id = 255;
syundo0730 16:e65c192b7ecf 26 stringstream sstr;
syundo0730 16:e65c192b7ecf 27 sstr << getc_wait();
syundo0730 16:e65c192b7ecf 28 sstr >> id;
syundo0730 16:e65c192b7ecf 29 serial->printf("id = %d \r\n", id);
syundo0730 16:e65c192b7ecf 30 return id;
syundo0730 16:e65c192b7ecf 31 }
syundo0730 16:e65c192b7ecf 32
syundo0730 16:e65c192b7ecf 33 uint16_t SCI::getservoval()
syundo0730 16:e65c192b7ecf 34 {
syundo0730 16:e65c192b7ecf 35 uint16_t val = 1500;
syundo0730 16:e65c192b7ecf 36 stringstream sstr;
syundo0730 16:e65c192b7ecf 37 while (!serial->readable());
syundo0730 16:e65c192b7ecf 38 for (int i = 0; i < 4; ++i) {
syundo0730 13:711f74b2fa33 39 sstr << getc_wait();
syundo0730 12:6cd135bf03bd 40 }
syundo0730 16:e65c192b7ecf 41 sstr >> val;
syundo0730 16:e65c192b7ecf 42 serial->printf("val:%d", val);
syundo0730 16:e65c192b7ecf 43 serial->printf("\r\n");
syundo0730 16:e65c192b7ecf 44 return val;
syundo0730 12:6cd135bf03bd 45 }
syundo0730 12:6cd135bf03bd 46
syundo0730 12:6cd135bf03bd 47 char SCI::getc_wait()
syundo0730 12:6cd135bf03bd 48 {
syundo0730 16:e65c192b7ecf 49 while (!serial->readable());
syundo0730 13:711f74b2fa33 50 char val = serial->getc();
syundo0730 13:711f74b2fa33 51 return val;
syundo0730 12:6cd135bf03bd 52 }
syundo0730 12:6cd135bf03bd 53
syundo0730 12:6cd135bf03bd 54 char SCI::getc_nowait()
syundo0730 12:6cd135bf03bd 55 {
syundo0730 12:6cd135bf03bd 56 uint8_t buf = 0;
syundo0730 12:6cd135bf03bd 57 if (serial->readable()) {
syundo0730 12:6cd135bf03bd 58 buf = serial->getc();
syundo0730 12:6cd135bf03bd 59 }
syundo0730 12:6cd135bf03bd 60 return buf;
syundo0730 12:6cd135bf03bd 61 }
syundo0730 12:6cd135bf03bd 62
syundo0730 13:711f74b2fa33 63 void SCI::printf(char* str)
syundo0730 13:711f74b2fa33 64 {
syundo0730 13:711f74b2fa33 65 serial->printf(str);
syundo0730 13:711f74b2fa33 66 }
syundo0730 13:711f74b2fa33 67
syundo0730 16:e65c192b7ecf 68 /*uint16_t SCI::readint()
syundo0730 12:6cd135bf03bd 69 {
syundo0730 16:e65c192b7ecf 70 uint8_t buff[2];
syundo0730 16:e65c192b7ecf 71 buff[0] = getc_wait();
syundo0730 16:e65c192b7ecf 72 buff[1] = getc_wait();
syundo0730 12:6cd135bf03bd 73 uint16_t val;
syundo0730 12:6cd135bf03bd 74 val = (uint16_t)(buff[1] << 8) | (uint16_t)buff[0];
syundo0730 12:6cd135bf03bd 75 return val;
syundo0730 16:e65c192b7ecf 76 }*/
syundo0730 12:6cd135bf03bd 77
syundo0730 16:e65c192b7ecf 78 /*void sendint(uint16_t val)
syundo0730 12:6cd135bf03bd 79 {
syundo0730 12:6cd135bf03bd 80 uint8_t buff[16];
syundo0730 12:6cd135bf03bd 81 buff[0] = (uint8_t)(val & 0x00FF);
syundo0730 12:6cd135bf03bd 82 buff[1] = (uint8_t)(val >> 8);
syundo0730 12:6cd135bf03bd 83 pc.putc(buff[0]);
syundo0730 12:6cd135bf03bd 84 pc.putc(buff[1]);
syundo0730 12:6cd135bf03bd 85 }*/