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:
- 2:d19d83df0d15
- Parent:
- 1:f43ebe88228e
- Child:
- 3:1bceed8a22d0
--- a/main.cpp Fri Sep 07 15:52:16 2018 +0000
+++ b/main.cpp Sat Sep 15 06:30:49 2018 +0000
@@ -2,23 +2,23 @@
#include "HX711.hpp"
#include "Dynamixel.h"
-HX711 hx711(p21, p22);
+HX711 hx711(p21, p22); //data, clk
Serial pc(USBTX, USBRX);
Dynamixel motor(p13,p14,p15,0xFE,57600);
Timer timeStamp;
-
+int motorspeed = 0;
//--------------------HX711
void calibrate(float gram){
hx711.setScale(1.f);
hx711.tare();
//この辺をProcessing用に組み替える
- printf("place the weight and put any key\n");
+ printf("place the weight and push any button\n");
char c = pc.getc();
float natural = hx711.readGram();
float calibVal = natural / gram;
hx711.setScale(calibVal);
- //printf("calibrated! %f %f %d\n", calibVal, natural, hx711.read());
+ printf("calibrated! %f %f %d\n", calibVal, natural, hx711.read());
}
@@ -64,19 +64,38 @@
case 'm': //モータ速度設定
char val_buf[20]; //数値受信用バッファ
- char *p;
+ char rx_data; //シリアル受信
+ motorspeed = 0; //モータ速度を一旦初期化
+ int i=0;
+ do{
+ rx_data = pc.getc(); //数値を取得
+ val_buf[i] = rx_data; //1文字を文字列に格納
+ i++;
+ }while(rx_data != ';'); //入力終了コマンド";"がきたら終了
+ i=0;
+ while(val_buf[i] != ';'){
+ //int型に変換
+ motorspeed *= 10;
+ motorspeed += (val_buf[i] - '0');
+ i++;
+ }
+ pc.printf("%d\n", motorspeed);
+ //WIP
break;
default:
+ pc.printf("fuck %c\n", c);
break;
}
}
int main() {
+ pc.attach(pc_rx, Serial::RxIrq);
pc.baud(115200);
//ホイールモードにするための設定
motor.setAngleLimit(0, ADDRESS_CW_ANGLE_LIMIT);
motor.setAngleLimit(0, ADDRESS_CCW_ANGLE_LIMIT);
+ move(0);
float gram = 0;
hx711.setScale(1.f);
@@ -85,7 +104,8 @@
timeStamp.reset();
while(1) {
- gram = hx711.readGram(3); //平均回数
- pc.printf(">%f,%f\n", gram, timeStamp.read()); //(WIP)Processingに送るデータ format: >(gram),(Time)
+ gram = hx711.readGram(1); //平均回数
+ pc.printf(">%.4f,%.2f\n", gram, timeStamp.read()); //(WIP)Processingに送るデータ format: >(gram),(Time)
+ //wait_ms(10);
}
}