Controlor for Humanoid. Walking trajectory generator, sensor reflection etc.

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

Committer:
syundo0730
Date:
Fri Nov 22 00:30:42 2013 +0000
Revision:
23:0927e605af4b
Parent:
22:bf5aa20b9df0
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
syundo0730 22:bf5aa20b9df0 1 #include <sstream>
syundo0730 22:bf5aa20b9df0 2
syundo0730 22:bf5aa20b9df0 3 #include "Console.h"
syundo0730 22:bf5aa20b9df0 4
syundo0730 22:bf5aa20b9df0 5 Console::Console(PinName tx, PinName rx)
syundo0730 22:bf5aa20b9df0 6 {
syundo0730 22:bf5aa20b9df0 7 serial = new Serial(tx, rx);
syundo0730 22:bf5aa20b9df0 8 }
syundo0730 22:bf5aa20b9df0 9
syundo0730 22:bf5aa20b9df0 10 Console::~Console()
syundo0730 22:bf5aa20b9df0 11 {
syundo0730 22:bf5aa20b9df0 12 delete serial;
syundo0730 22:bf5aa20b9df0 13 }
syundo0730 22:bf5aa20b9df0 14
syundo0730 22:bf5aa20b9df0 15 uint8_t Console::getheader()
syundo0730 22:bf5aa20b9df0 16 {
syundo0730 22:bf5aa20b9df0 17 uint8_t comm = getc_nowait();
syundo0730 22:bf5aa20b9df0 18 if (comm != 0) {
syundo0730 22:bf5aa20b9df0 19 serial->printf("Mode:%c \r\n", comm);
syundo0730 22:bf5aa20b9df0 20 }
syundo0730 22:bf5aa20b9df0 21 return comm;
syundo0730 22:bf5aa20b9df0 22 }
syundo0730 22:bf5aa20b9df0 23
syundo0730 22:bf5aa20b9df0 24 int Console::getid()
syundo0730 22:bf5aa20b9df0 25 {
syundo0730 22:bf5aa20b9df0 26 int id;
syundo0730 22:bf5aa20b9df0 27 stringstream sstr;
syundo0730 22:bf5aa20b9df0 28 serial->printf("Enter the ID: \r\n");
syundo0730 22:bf5aa20b9df0 29 sstr << getc_wait();
syundo0730 22:bf5aa20b9df0 30 sstr >> id;
syundo0730 22:bf5aa20b9df0 31 serial->printf("Servo ID:%d \r\n", id);
syundo0730 22:bf5aa20b9df0 32 return id;
syundo0730 22:bf5aa20b9df0 33 }
syundo0730 22:bf5aa20b9df0 34
syundo0730 22:bf5aa20b9df0 35 uint16_t Console::get_int_cr()
syundo0730 22:bf5aa20b9df0 36 {
syundo0730 22:bf5aa20b9df0 37 stringstream sstr;
syundo0730 22:bf5aa20b9df0 38 serial->printf("Enter the Servo value. And push Enter.: \r\n");
syundo0730 22:bf5aa20b9df0 39 while (1) {
syundo0730 22:bf5aa20b9df0 40 uint8_t tmp = getc_wait();
syundo0730 22:bf5aa20b9df0 41 serial->printf("%c", tmp);
syundo0730 22:bf5aa20b9df0 42 if (tmp == '\r') {
syundo0730 22:bf5aa20b9df0 43 serial->printf("\r\n");
syundo0730 22:bf5aa20b9df0 44 break;
syundo0730 22:bf5aa20b9df0 45 }
syundo0730 22:bf5aa20b9df0 46 sstr << tmp;
syundo0730 22:bf5aa20b9df0 47 }
syundo0730 22:bf5aa20b9df0 48 uint16_t val;
syundo0730 22:bf5aa20b9df0 49 sstr >> val;
syundo0730 22:bf5aa20b9df0 50 serial->printf("Servo value:%d \r\n", val);
syundo0730 22:bf5aa20b9df0 51 return val;
syundo0730 22:bf5aa20b9df0 52 }
syundo0730 22:bf5aa20b9df0 53
syundo0730 23:0927e605af4b 54 float Console::get_float_cr()
syundo0730 23:0927e605af4b 55 {
syundo0730 23:0927e605af4b 56 stringstream sstr;
syundo0730 23:0927e605af4b 57 serial->printf("Enter the float parameter. And push Enter.: \r\n");
syundo0730 23:0927e605af4b 58 while (1) {
syundo0730 23:0927e605af4b 59 uint8_t tmp = getc_wait();
syundo0730 23:0927e605af4b 60 serial->printf("%c", tmp);
syundo0730 23:0927e605af4b 61 if (tmp == '\r') {
syundo0730 23:0927e605af4b 62 serial->printf("\r\n");
syundo0730 23:0927e605af4b 63 break;
syundo0730 23:0927e605af4b 64 }
syundo0730 23:0927e605af4b 65 sstr << tmp;
syundo0730 23:0927e605af4b 66 }
syundo0730 23:0927e605af4b 67 float val;
syundo0730 23:0927e605af4b 68 sstr >> val;
syundo0730 23:0927e605af4b 69 serial->printf("parameter:%f \r\n", val);
syundo0730 23:0927e605af4b 70 return val;
syundo0730 23:0927e605af4b 71 }
syundo0730 23:0927e605af4b 72
syundo0730 22:bf5aa20b9df0 73 uint8_t Console::getc_wait()
syundo0730 22:bf5aa20b9df0 74 {
syundo0730 22:bf5aa20b9df0 75 while (!serial->readable());
syundo0730 22:bf5aa20b9df0 76 uint8_t val = serial->getc();
syundo0730 22:bf5aa20b9df0 77 return val;
syundo0730 22:bf5aa20b9df0 78 }
syundo0730 22:bf5aa20b9df0 79
syundo0730 22:bf5aa20b9df0 80 uint8_t Console::getc_nowait()
syundo0730 22:bf5aa20b9df0 81 {
syundo0730 22:bf5aa20b9df0 82 uint8_t buf = 0;
syundo0730 22:bf5aa20b9df0 83 if (serial->readable()) {
syundo0730 22:bf5aa20b9df0 84 buf = serial->getc();
syundo0730 22:bf5aa20b9df0 85 }
syundo0730 22:bf5aa20b9df0 86 return buf;
syundo0730 22:bf5aa20b9df0 87 }
syundo0730 22:bf5aa20b9df0 88
syundo0730 22:bf5aa20b9df0 89 void Console::printf(char* str)
syundo0730 22:bf5aa20b9df0 90 {
syundo0730 22:bf5aa20b9df0 91 serial->printf(str);
syundo0730 22:bf5aa20b9df0 92 }
syundo0730 22:bf5aa20b9df0 93
syundo0730 23:0927e605af4b 94 void Console::showOnline(OnlineMotion* on) {
syundo0730 23:0927e605af4b 95 serial->printf("T:%f\r\n", on->T);
syundo0730 23:0927e605af4b 96 serial->printf("h:%f\r\n", on->h);
syundo0730 23:0927e605af4b 97 serial->printf("side:%f\r\n", on->side);
syundo0730 23:0927e605af4b 98 serial->printf("stride:%f\r\n", on->stride);
syundo0730 23:0927e605af4b 99 serial->printf("up:%f\r\n", on->up);
syundo0730 23:0927e605af4b 100 }
syundo0730 23:0927e605af4b 101
syundo0730 22:bf5aa20b9df0 102 /*uint16_t Console::readint()
syundo0730 22:bf5aa20b9df0 103 {
syundo0730 22:bf5aa20b9df0 104 uint8_t buff[2];
syundo0730 22:bf5aa20b9df0 105 buff[0] = getc_wait();
syundo0730 22:bf5aa20b9df0 106 buff[1] = getc_wait();
syundo0730 22:bf5aa20b9df0 107 uint16_t val;
syundo0730 22:bf5aa20b9df0 108 val = (uint16_t)(buff[1] << 8) | (uint16_t)buff[0];
syundo0730 22:bf5aa20b9df0 109 return val;
syundo0730 22:bf5aa20b9df0 110 }*/
syundo0730 22:bf5aa20b9df0 111
syundo0730 22:bf5aa20b9df0 112 /*void sendint(uint16_t val)
syundo0730 22:bf5aa20b9df0 113 {
syundo0730 22:bf5aa20b9df0 114 uint8_t buff[16];
syundo0730 22:bf5aa20b9df0 115 buff[0] = (uint8_t)(val & 0x00FF);
syundo0730 22:bf5aa20b9df0 116 buff[1] = (uint8_t)(val >> 8);
syundo0730 22:bf5aa20b9df0 117 pc.putc(buff[0]);
syundo0730 22:bf5aa20b9df0 118 pc.putc(buff[1]);
syundo0730 23:0927e605af4b 119 }*/