おためしらいぶらり Q-rover-Kaiを50行以内で動かすという強い気持ち 使用非推奨 動作未確認 単純なPWM動作のライブラリ化実験用
Revision 0:48d84c228105, committed 2017-12-06
- Comitter:
- KOTAROYamamoto
- Date:
- Wed Dec 06 07:07:32 2017 +0000
- Commit message:
- ?????????
Changed in this revision
QMotor.cpp | Show annotated file Show diff for this revision Revisions of this file |
QMotor.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 48d84c228105 QMotor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QMotor.cpp Wed Dec 06 07:07:32 2017 +0000 @@ -0,0 +1,166 @@ +#include "mbed.h" +#include "QMotor.h" + +QMotor::QMotor(PinName R1,PinName R2,PinName L1,PinName L2):_R1(R1),_R2(R2),_L1(L1),_L2(L2){ + _R1=0.0;//R1を初期化 + _R2=0.0;//R2を初期化 + _L1=0.0;//L1を初期化 + _L2=0.0;//L2を初期化 + +} + +void QMotor::Front1(){ //直進部 + _R1=1.0; + _R2=0.0; + _L1=1.0; + _L2=0.0; + wait(25.000); + + _R1=1.0; + _R2=1.0; + _L1=1.0; + _L2=1.0; + wait(0.200); + _R1=0.0; + _R2=0.0; + _L1=0.0; + _L2=0.0; +} + +void QMotor::Front2(){ //直進部 + _R1=0.5; + _R2=0.0; + _L1=0.5; + _L2=0.0; + wait(5.000); + + _R1=1.0; + _R2=1.0; + _L1=1.0; + _L2=1.0; + wait(0.200); + _R1=0.0; + _R2=0.0; + _L1=0.0; + _L2=0.0; +} +void QMotor::Right1(float an,float san){ //第一while関数右折部 + //sdprint(" an="); + //sdprint(an); + //sdprint(" R1 "); + //xbee.printf("COMMAND:Right1\n"); + _R1=1.0; + _R2=0.0; + wait(-an*san); + + _R1=1.0; + _R2=1.0; + wait(0.200); + _R1=0.0; + _R2=0.0; + } + + void QMotor::Right2(float an,float san){ //第二while関数右折部 + //sdprint(" an="); + //sdprint(an); + //sdprint(" R2 "); + //xbee.printf("COMMAND:Right2\n"); + //analogWrite(5,76.5);//Lモーターを30%出力で回転 + _R1=1.0; + _R2=0.0; + wait(-an*san); + + _R1=1.0; + _R2=1.0; + wait(0.200); + _R1=0.0; + _R2=0.0; + } + + + void QMotor::Left1(float an,float san){ //第一while関数左折部 + //sdprint(" an="); + //sdprint(an); + //sdprint(" L1 "); + //xbee.printf("COMMAND:Left1\n"); + _L1=1.0; + _L2=0.0; + wait(an*san); + + _L1=1.0; + _L2=1.0; + wait(0.200); + _L1=0.0; + _L2=0.0; + } + + void QMotor::Left2(float an,float san){ //第二while関数左折部 + //sdprint(" an="); + //sdprint(an); + //sdprint(" L2 "); + //xbee.printf("COMMAND:Left2\n"); + //analogWrite(6,76.5);//Rモーターを30%出力で回転 + _L1=1.0; + _L2=0.0; + wait(an*san); + + _L1=1.0; + _L2=1.0; + wait(0.200); + _L1=0.0; + _L2=0.0; + } + +void QMotor::Reverse(){ //姿勢回復機動 + _R1=0.0; + _R2=1.0; + _L1=0.0; + _L2=1.0; + wait(15.000); + _R1=1.0; + _R2=0.0; + _L1=1.0; + _L2=0.0; + wait(5.000); + _R1=0.0; + _R2=0.0; + _L1=0.0; + _L2=0.0; +} + +void QMotor::Stack(){ //スタック回避挙動 + _R1=1.0; + _R2=0.0; + _L1=0.0; + _L2=1.0; + wait(5.000); + + _R1=1.0; + _R2=1.0; + _L1=1.0; + _L2=1.0; + wait(5.000); + _L1=0.0; + _L2=0.0; + _R1=0.0; + _R2=0.0; + } + + void QMotor::Fred(){ //冗長系測角用直進部 + _R1=1.0; + _R2=0.0; + _L1=1.0; + _L2=0.0; + wait(10.000); + + _R1=1.0; + _R2=1.0; + _L1=1.0; + _L2=1.0; + wait(0.200); + _R1=0.0; + _R2=0.0; + _L1=0.0; + _L2=0.0; + } + \ No newline at end of file
diff -r 000000000000 -r 48d84c228105 QMotor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QMotor.h Wed Dec 06 07:07:32 2017 +0000 @@ -0,0 +1,41 @@ +/*********** +*絶対にQ-rover-Kaiを50行以内で動かすという強い気持ち +***********/ +#include "mbed.h" + +#ifndef QMOTOR_H +#define QMOTOR_H + + + +class QMotor{ + public: + QMotor(PinName R1,PinName R2,PinName L1,PinName L2); + + void Front1(); + void Front2(); + void Right1(float an,float san); + void Right2(float an,float san); + void Left1(float an,float san); + void Left2(float an,float san); + void Reverse(); + void Stack(); + void Fred(); + + private: + PwmOut _R1; + PwmOut _R2; + PwmOut _L1; + PwmOut _L2; +}; +void Front1(); +void Front2(); +void Right1(float *sec); +void Right2(float *sec); +void Left1(float *sec); +void Left2(float *sec); +void Reverse(); +void Fred(); +void Stack(); + +#endif \ No newline at end of file