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.
Diff: main.cpp
- Revision:
- 1:f43ebe88228e
- Parent:
- 0:4e684157ecca
- Child:
- 2:d19d83df0d15
--- a/main.cpp Thu Sep 06 12:54:00 2018 +0000
+++ b/main.cpp Fri Sep 07 15:52:16 2018 +0000
@@ -5,16 +5,7 @@
HX711 hx711(p21, p22);
Serial pc(USBTX, USBRX);
Dynamixel motor(p13,p14,p15,0xFE,57600);
-
-//Dynamixel回転方向対応用
-//多分11bitのうちMSBが符号,最上位で回転方向を指定している
-move(int speed){
- if(speed >= 0)
- motor.setSpeed(speed);
- else{
- motor.setSpeed(-1*speed+1024); //11bitのうちMSBが符号
- }
-}
+Timer timeStamp;
//--------------------HX711
void calibrate(float gram){
@@ -31,10 +22,70 @@
}
+//Dynamixel回転方向対応用
+//多分11bitのうちMSBが符号,最上位で回転方向を指定している
+void move(int speed){
+ if(speed >= 0)
+ motor.setSpeed(speed);
+ else{
+ motor.setSpeed(-1*speed+1024); //11bitのうちMSBが符号
+ }
+}
+
+//シリアル受信時
+void pc_rx(){
+ char c = pc.getc(); //P5からの入力
+
+ switch(c){
+ case 'c': //キャリブレーション
+ calibrate(50.0);
+ break;
+ case 's': //計測開始
+ timeStamp.reset();
+ move(-20); //(WIP)
+ timeStamp.start();
+ break;
+ case 'e': //計測終了
+ move(0); //(WIP)
+ timeStamp.stop();
+ break;
+ case 'z': //ゼロ点オフセット
+ hx711.tare();
+ break;
+ case 'l': //モータ左回転
+ move(-20); //(WIP)
+ break;
+ case 'r': //モータ右回転
+ move(20); //(WIP)
+ break;
+ case 'q': //モータ停止
+ move(0);
+ break;
+
+ case 'm': //モータ速度設定
+ char val_buf[20]; //数値受信用バッファ
+ char *p;
+ break;
+
+ default:
+ break;
+ }
+}
+
int main() {
+ pc.baud(115200);
//ホイールモードにするための設定
motor.setAngleLimit(0, ADDRESS_CW_ANGLE_LIMIT);
motor.setAngleLimit(0, ADDRESS_CCW_ANGLE_LIMIT);
+
+ float gram = 0;
+ hx711.setScale(1.f);
+ hx711.tare();
+
+ timeStamp.reset();
+
while(1) {
+ gram = hx711.readGram(3); //平均回数
+ pc.printf(">%f,%f\n", gram, timeStamp.read()); //(WIP)Processingに送るデータ format: >(gram),(Time)
}
}