夏ロボ用

Dependencies:   QEI mbed

Files at this revision

API Documentation at this revision

Comitter:
kurt
Date:
Sat Sep 07 06:34:29 2013 +0000
Commit message:
for publish
;

Changed in this revision

QEI.lib Show annotated file Show diff for this revision Revisions of this file
init.cpp Show annotated file Show diff for this revision Revisions of this file
init.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 7d18a91d0d19 QEI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI.lib	Sat Sep 07 06:34:29 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/aberk/code/QEI/#5c2ad81551aa
diff -r 000000000000 -r 7d18a91d0d19 init.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/init.cpp	Sat Sep 07 06:34:29 2013 +0000
@@ -0,0 +1,77 @@
+#include "init.h"
+#include "QEI.h"
+
+
+DigitalOut  MOTOR_POWER(PTC10);
+
+PwmOut  PWM0(PTC9);
+PwmOut  PWM1(PTC8);
+PwmOut  PWM2(PTA5);
+PwmOut  PWM3(PTA4);
+PwmOut  PWM4(PTA12);
+PwmOut  PWM5(PTD4);
+AnalogIn    AD0(PTB0);
+AnalogIn    AD1(PTB1);
+AnalogIn    AD2(PTB2);
+AnalogIn    AD3(PTB3);
+AnalogIn    AD4(PTC2);
+
+DigitalOut  OUT0(PTC6);
+//DigitalIn IN0(PTC6);
+DigitalOut  OUT1(PTC5);
+//DigitalIn IN1(PTC5);
+DigitalOut  OUT2(PTC4);
+//DigitalIn IN2(PTC4);
+DigitalOut  OUT3(PTC3);
+//DigitalIn IN3(PTC3);
+DigitalOut  OUT4(PTC0);
+//DigitalIn IN4(PTC0);
+DigitalOut  OUT5(PTC7);
+//DigitalIn IN5(PTC7);
+
+Serial pc(USBTX, USBRX);
+
+QEI         ENC0(PTD6, PTD7, NC, 624, QEI::X2_ENCODING);
+QEI         ENC1(PTD3, PTD1, NC, 624, QEI::X2_ENCODING);
+QEI         ENC2(PTA13, PTD5, NC, 624, QEI::X2_ENCODING);
+QEI         ENC3(PTD0, PTD2, NC, 624, QEI::X2_ENCODING);
+
+I2C         i2c0(PTE0,PTE1);
+
+DigitalIn   SW0(PTE29);
+DigitalIn   SW1(PTE30);
+
+DigitalOut  rled(LED_RED);
+DigitalOut  gled(LED_GREEN);
+DigitalOut  bled(LED_BLUE);
+
+void InitBoard(){
+    SW0.mode(PullUp);
+    SW1.mode(PullUp);
+    i2c0.frequency(1000000);
+    MOTOR_POWER = 1;
+}
+
+Timer AdCycle;
+
+void AdjustCycle(int t_us){
+    if(AdCycle.read_us() == 0) AdCycle.start();
+
+    if(AdCycle.read_us()>t_us)gled=0;
+    else                      gled=1;
+    while(AdCycle.read_us()<=t_us);
+    AdCycle.reset();
+}
+
+int Limit(int value,int max,int min) {
+    if (value>max)return max;
+    if (value<min)return min;
+    else          return value;
+}
+
+double Limit_d(double value,double max,double min) {
+    if (value>max)return max;
+    if (value<min)return min;
+    else          return value;
+}
+
diff -r 000000000000 -r 7d18a91d0d19 init.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/init.h	Sat Sep 07 06:34:29 2013 +0000
@@ -0,0 +1,57 @@
+#ifndef INIT_H_
+#define INIT_H_
+
+#include "QEI.h"
+
+
+extern PwmOut  PWM0;
+extern PwmOut  PWM1;
+extern PwmOut  PWM2;
+extern PwmOut  PWM3;
+extern PwmOut  PWM4;
+extern PwmOut  PWM5;
+extern AnalogIn    AD0;
+extern AnalogIn    AD1;
+extern AnalogIn    AD2;
+extern AnalogIn    AD3;
+extern AnalogIn    AD4;
+
+extern DigitalOut  OUT0;
+extern DigitalIn IN0;
+extern DigitalOut  OUT1;
+extern DigitalIn IN1;
+extern DigitalOut  OUT2;
+extern DigitalIn IN2;
+extern DigitalOut  OUT3;
+extern DigitalIn IN3;
+extern DigitalOut  OUT4;
+extern DigitalIn IN4;
+extern DigitalOut  OUT5;
+extern DigitalIn IN5;
+
+extern QEI         ENC0;
+extern QEI         ENC1;
+extern QEI         ENC2;
+extern QEI         ENC3;
+
+extern Serial      pc;
+
+extern I2C         i2c0;
+
+extern DigitalIn   SW0;
+extern DigitalIn   SW1;
+
+extern DigitalOut  rled;
+extern DigitalOut  gled;
+extern DigitalOut  bled;
+
+
+
+extern void InitBoard();
+extern void AdjustCycle(int t_us);
+extern int Limit(int value,int max,int min);
+extern double Limit_d(double value,double max,double min);
+
+
+
+#endif /* INIT_H_ */
\ No newline at end of file
diff -r 000000000000 -r 7d18a91d0d19 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Sep 07 06:34:29 2013 +0000
@@ -0,0 +1,18 @@
+#include "mbed.h"
+#include "init.h"
+
+int main() {
+    pc.baud(921600/*9600*/);//シリアルポートpcは定義済み
+    pc.printf("\n\r%s ", __TIME__);
+    pc.printf("%s\n\r", __DATE__);
+    pc.printf("Hello World!\n\r");
+
+    InitBoard();//モーターをつなぐPWMの周期とデューティを設定してから起動することを推奨
+
+    while(1) {
+        AdjustCycle(10000);
+        /*-----------------------
+        ここにプログラムを書く
+        --------------------------*/
+    }
+}
diff -r 000000000000 -r 7d18a91d0d19 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Sep 07 06:34:29 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7e6c9f46b3bd
\ No newline at end of file