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.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 1:1b3526a1ae3f
- Parent:
- 0:ef944a0446ee
--- a/main.cpp Wed Dec 11 05:56:32 2019 +0000
+++ b/main.cpp Wed Dec 11 08:16:26 2019 +0000
@@ -38,27 +38,34 @@
//AnalogIn schmitt(A5);
int main() {
- enc_R.rise(&event_handler_R);
- enc_R.fall(&event_handler_R);
- enc_L.rise(&event_handler_L);
- enc_L.fall(&event_handler_L);
+
motorStop(AIN1,AIN2);
motorStop(BIN1,BIN2);
float pre_counter_R = 0;
float pre_counter_L = 0;
+
while(1) {//組み込み型のプログラムは無限ループになるようにする。(終わってはいけない)
- for(float duty = 0.50;duty==0.0;duty-=0.01){
- duty = 0.155;
+ float duty = 0.50;
+
+ motorReverse(AIN1,AIN2,duty);//逆転のほうが制御しやすいので前進時は逆転を使用
+ motorReverse(BIN1,BIN2,duty);
+ printf("ready\n");
+ wait(3);
+ printf("go\n");
+ for(duty;duty>0.0;duty-=0.01){
+ enc_R.rise(&event_handler_R);
+ enc_R.fall(&event_handler_R);
+ enc_L.rise(&event_handler_L);
+ enc_L.fall(&event_handler_L);
motorReverse(AIN1,AIN2,duty);//逆転のほうが制御しやすいので前進時は逆転を使用
motorReverse(BIN1,BIN2,duty);
wait(2);//回転が安定するまで待つ
- pre_counter_R = counter_R;
- pre_counter_L = counter_L;
- wait(1);
printf("duty value:%f\n",duty);
printf("rotations per second(R_tire):%f\n",(counter_R-pre_counter_R)/24.0/38.2);//1秒間あたりのタイヤの回転数
printf("rotations per second(L_tire):%f\n",(counter_L-pre_counter_L)/24.0/38.2);
+ pre_counter_R = counter_R;
+ pre_counter_L = counter_L;
}
}