Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Nucleo_CaitSith_Firmware by
Diff: main.cpp
- Revision:
- 4:039a7d1ce3e9
- Parent:
- 3:9ac9fdf1856e
- Child:
- 5:4c87a8401f7c
--- a/main.cpp Sat Nov 08 02:45:59 2014 +0000
+++ b/main.cpp Sat Jan 24 17:41:21 2015 +0000
@@ -5,6 +5,9 @@
//#include <RobotArm.h>
#include <def_resources.h>
#include <Serial.h>
+#include "Roomba.h"
+#include "EventArg.h"
+
/*
@@ -26,21 +29,73 @@
int oyatsuCnt = 0;
+EventArg e;
+
int serial_gets(char *buffer, int size);
-int initialize();
+void initialize();
+
+//void moveServo()
+//{
+// shakeHead.moveServo();
+// nodHead.moveServo();
+// leftArm.moveServo();
+// leftShoulder.moveServo();
+// rightArm.moveServo();
+// rightShoulder.moveServo();
+//}
+
+Ticker mTick;
+
+Roomba nyandaBase(SERIAL_TX, SERIAL_RX, PA_14);
int main() {
+ pc.baud(115200);
+ initialize();
+ debugled = 1;
+ //mTick.attach_us(&moveServo, 10000);
- initialize();
+
+ Roomba* cp = new Roomba(SERIAL_TX, SERIAL_RX, LED1);//Class pointor
+ void (Roomba::*fp)(void) = &Roomba::serialReceiveCallback;
+
+ //<戻り値の型> (<クラス名>::*<変数名>(<引数リスト>);
+
+ //fp = cp->serialReceiveCallback();
+
+ //ticker.attach(&cp, cp->serialReceiveCallback, 0.1);
+
+
+ //(cp->*fp)();//クラスポインタとメンバポインタ両方を使うメソッド呼び出し?なにに使うの?
+
+ //ticker.attach(&cp, (cp->*fp)(), 0.1);
+ //Roomba* cp = new Roomba(SERIAL_TX, SERIAL_RX, LED1);//Class pointor
+ //void (Roomba::*fp)(void) = &Roomba::serialReceiveCallback;
+
+ //<戻り値の型> (<クラス名>::*<変数名>(<引数リスト>);
+
+ //fp = cp->serialReceiveCallback();
+
+ //ticker.attach(&cp, cp->serialReceiveCallback, 0.1);
+
+
+ //(cp->*fp)();//クラスポインタとメンバポインタ両方を使うメソッド呼び出し?なにに使うの?
+
+ //ticker.attach(&cp, (cp->*fp)(), 0.1);
+
+ //mTick.attach(Roomba, &nyandaBase.periodicCallback, 0.1);
+
while(1) {
char buffer[BUFFER_SIZE];
- // コマンド受信
+ // コマンド受信
int size = serial_gets(buffer, BUFFER_SIZE);
+
if (size > 0) {
- //pc.printf("%s", buffer);
+#ifdef DEBUG
+ pc.printf("%s", buffer);
+#endif
// コマンド判定
if (strncmp(buffer, "CT", 2) == 0) {
@@ -52,9 +107,8 @@
ret = true;
} else if (size >= 3) {
-
-
- switch (buffer[2]) {
+
+ switch (buffer[2]) {
case 'Z':
initialize();
@@ -74,6 +128,31 @@
}
break;
+
+ case 'M':
+
+ ret = true;
+
+ //CTM+500-500
+
+ char buff[4+1];
+ int temp;
+
+ //printf("Param:%s\n", before);
+ strncpy(buff, buffer + 3, 4);
+ buff[4] = '\0';
+ //printf("ASC:%s\n", buff);
+ temp = atoi(buff);
+ e.leftWheetVelocity = temp;
+
+ //printf("Param:%s\n", before);
+ strncpy(buff, (char*)buffer[3+4], 4);
+ buff[4] = '\0';
+ //printf("ASC:%s\n", buff);
+ temp = atoi(buff);
+ e.rightWheelVelocity = temp;
+
+ break;
case 'O':
@@ -164,14 +243,17 @@
}
}
}
-
+ //シリアル受信待ちをwihelで待っているので、定期送信は不可能
+// nyandaBase.periodicCallback(e);
+// debugled != debugled;
+// //そもそもTickerで書ける?引数付きのメソッドをattachできるのか
+// //attach第2引数のインスタンスメソッドのポインタは引数付きとか書けるのか
+// wait_ms(100);
}
}
-int initialize() {
- myled = 1;
-
+void initialize() {
nyandaLight = 0;
shakeHead.setAngle(0);
@@ -180,6 +262,7 @@
leftShoulder.setAngle(0);
rightArm.setAngle(0);
rightShoulder.setAngle(0);
+
}
@@ -201,6 +284,7 @@
--i;
}
if (buffer[i] == '\n') {
+
break;
}
++i;
@@ -212,3 +296,75 @@
//pc.printf("%s", buffer);
return i;
}
+
+
+
+///*/*
+// *
+// */
+//int getMoveCommand(char opcode, char* before, char* converted)
+//{
+// char buff[10];
+// int temp;
+// int cont = 0;
+//
+// converted[cont] = opcode;
+// ++cont;
+// cont = cont + convertHexToAscString(before, 4, converted + cont);
+// cont = cont + convertHexToAscString(before + 4, 4, converted + cont);
+// converted[cont] = '\0';
+//
+//#ifdef DEBUG
+// int i = 0;
+// for (i = 0; i < cont; i++) {
+// printf("%x\n", *(converted + i));
+// }
+//#endif
+//
+// return strlen(converted);
+//}*/
+//
+////TBD:Create Utility Class. And move under method add static
+//int convertDecToAsc(char* target, int length, int* converted) {
+// char buff[length + 1];
+// int temp;
+//
+// //strncpy(buff, before, length);
+// buff[length] = '\0';
+// //printf("ASC:%s\n", buff);
+//
+// temp = atoi(buff);
+// //printf("DEC:%d\n", temp);
+//
+// //converted = temp;
+//
+// return 0;//strlen(converted);
+//}
+
+//
+///*
+// *
+// */
+//int convertHexToAscString(char* before, int length, char* converted)
+//{
+// char buff[length + 1];
+// int temp;
+//
+// printf("Param:%s\n", before);
+//
+// strncpy(buff, before, length);
+// buff[length] = '\0';
+// printf("ASC:%s\n", buff);
+//
+// temp = atoi(buff);
+// printf("DEC:%d\n", temp);
+//
+// converted[0] = ((temp & 0xFF00) >> 8);
+// converted[1] = (temp & 0xFF);
+// converted[2] = '\0';
+// printf("HEX(MSB):%x\n", converted[0]);
+// printf("HEX(LSB):%x\n", converted[1]);
+//
+// return strlen(converted);
+//}
+//
