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:
- 5:4c87a8401f7c
- Parent:
- 4:039a7d1ce3e9
- Child:
- 6:a3829299dfd5
--- a/main.cpp Sat Jan 24 17:41:21 2015 +0000
+++ b/main.cpp Sun Jan 25 07:45:04 2015 +0000
@@ -1,10 +1,11 @@
#include <mbed.h>
+#include <Serial.h>
+
+#include <def_resources.h>
#include <PwmServo.h>
#include <ExtendedServo.h>
#include <DelayServo.h>
//#include <RobotArm.h>
-#include <def_resources.h>
-#include <Serial.h>
#include "Roomba.h"
#include "EventArg.h"
@@ -19,7 +20,7 @@
*/
#define DEBUG
-#define BUFFER_SIZE 11
+#define BUFFER_SIZE 15
//#define COMMAND_TOTAL 3
@@ -55,40 +56,15 @@
debugled = 1;
//mTick.attach_us(&moveServo, 10000);
-
Roomba* cp = new Roomba(SERIAL_TX, SERIAL_RX, LED1);//Class pointor
- void (Roomba::*fp)(void) = &Roomba::serialReceiveCallback;
-
+ //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) {
@@ -107,10 +83,9 @@
ret = true;
} else if (size >= 3) {
-
+
switch (buffer[2]) {
- case 'Z':
-
+ case 'Z':
initialize();
ret = true;
@@ -138,25 +113,25 @@
char buff[4+1];
int temp;
- //printf("Param:%s\n", before);
+ //pc.printf("Param:%s\n", before);
strncpy(buff, buffer + 3, 4);
buff[4] = '\0';
- //printf("ASC:%s\n", buff);
+ //pc.printf("ASC:%s\n", buff);
temp = atoi(buff);
- e.leftWheetVelocity = temp;
-
+ e.leftWheetVelocity = temp;
//printf("Param:%s\n", before);
- strncpy(buff, (char*)buffer[3+4], 4);
+ strncpy(buff, buffer + 7, 4);//(char*)buffer[3+4]
buff[4] = '\0';
- //printf("ASC:%s\n", buff);
+ pc. printf("ASC:%s\n", buff);
temp = atoi(buff);
e.rightWheelVelocity = temp;
-
+
break;
case 'O':
ret = true;
+
if (buffer[3] == '0') {
oyatsuCnt = 0;
oyatsuFeeder.setAngle(0);
@@ -189,6 +164,7 @@
}
break;
+
case 'H':
int servoAngle = -1;
@@ -243,12 +219,9 @@
}
}
}
- //シリアル受信待ちをwihelで待っているので、定期送信は不可能
-// nyandaBase.periodicCallback(e);
-// debugled != debugled;
-// //そもそもTickerで書ける?引数付きのメソッドをattachできるのか
-// //attach第2引数のインスタンスメソッドのポインタは引数付きとか書けるのか
-// wait_ms(100);
+
+ nyandaBase.periodicCallback(e);//ルンバへ移動指示
+ wait_ms(100);
}
}
@@ -270,9 +243,9 @@
*
*/
int serial_gets(char *buffer, int size) {
- /*if (!pc.readable()) {
+ if (!pc.readable()) {
return 0;
- }*/
+ }
int i = 0;
while (i < size - 1) {
