2Chx3dof Magnetrometer supported M-Series Random Sequence Generator Servo Control

Dependencies:   mbed

Sampling Frequency

Sampling Frequency in main.cpp

#define SampleFreq     200   // [Hz]

Auto Stop Setting

Auto-stop Timer 15sec after

    // auto-stop when 15sec after
    if(smpl_cnt>3000){stop_dump();}

The number of 3000 means Sample Count. The number is given by SampleFreq[Hz] * Auto-Stop Time [sec].

M-Series Random Sequence

M-series Random Update Term in main.cpp

// M-series update flag
#define  M_TERM  200;

Unit is sample count.

cf.) 200 equals to 200 [samples] which equals to 1 [second] where SampleFreq = 200 [Hz}.

See above.

M-Series Random Servo Control

Files at this revision

API Documentation at this revision

Comitter:
mfurukawa
Date:
Wed Feb 10 21:59:00 2021 +0000
Branch:
MPU-9250-MagSensServo
Parent:
10:f5a805d998d6
Commit message:
e

Changed in this revision

KST_Servo.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
--- a/KST_Servo.h	Wed Feb 03 06:01:27 2021 +0000
+++ b/KST_Servo.h	Wed Feb 10 21:59:00 2021 +0000
@@ -48,9 +48,9 @@
 #define KST_SERVO_USEC_MIN  900 // -60deg
 
 #define KONDO_SERVO_KRS2572HV_USEC_MAX 3000 //  60deg
-#define KONDO_SERVO_KRS2572HV_USEC_180 2800 //  60deg
-#define KONDO_SERVO_KRS2572HV_USEC_MID 1750 //   0deg
-#define ONDOT_SERVO_KRS2572HV_USEC_MIN 1100 // -60deg
+#define KONDO_SERVO_KRS2572HV_USEC_180 2800 // 180deg
+#define KONDO_SERVO_KRS2572HV_USEC_90  1950 //  90deg
+#define ONDOT_SERVO_KRS2572HV_USEC_MIN 1100 //   0deg
 
 
 #endif //  __KST_SERVO_H__
\ No newline at end of file
--- a/main.cpp	Wed Feb 03 06:01:27 2021 +0000
+++ b/main.cpp	Wed Feb 10 21:59:00 2021 +0000
@@ -88,7 +88,7 @@
 Mseries m;
 
 // M-series update flag
-#define  M_TERM  100;
+#define  M_TERM  200;
 int  m_cnt = M_TERM;
 
 #define BINARY_MODE 0
@@ -97,6 +97,7 @@
 
 #define CSV_TITLE_COLUMN "smpl_cnt,time[sec],M_stat,accX,accY,accZ,gyroX,gyroY,gyroZ,magX,magY,magZ,accX,accY,accZ,gyroX,gyroY,gyroZ,magX,magY,magZ,\r\n"
 
+void stop_dump(void);
 
 void servo_test(void)
 {
@@ -104,7 +105,7 @@
         if(m.update())
             pwm_.pulsewidth_us(ONDOT_SERVO_KRS2572HV_USEC_MIN);
         else
-            pwm_.pulsewidth_us(KONDO_SERVO_KRS2572HV_USEC_180);
+            pwm_.pulsewidth_us(KONDO_SERVO_KRS2572HV_USEC_90);
         wait(.5);
 
     }
@@ -204,7 +205,7 @@
         if(m.get())
             pwm_.pulsewidth_us(ONDOT_SERVO_KRS2572HV_USEC_MIN);
         else
-            pwm_.pulsewidth_us(KONDO_SERVO_KRS2572HV_USEC_180);
+            pwm_.pulsewidth_us(KONDO_SERVO_KRS2572HV_USEC_90);
         m_cnt = M_TERM;
     }
 
@@ -267,6 +268,16 @@
 
     putc(13, stdout);  //0x0d CR(復帰)
     putc(10, stdout);  //0x0a LF(改行)
+    
+    // auto-stop when 15sec after
+    if(smpl_cnt>3000){stop_dump();}
+}
+
+void stop_dump(void)
+{
+    ticker.detach();
+    timer.stop();
+    smpl_cnt = 0;
 }
 
 int main()
@@ -282,9 +293,7 @@
 
             switch(c) {
                 case 'r':
-                    ticker.detach();
-                    timer.stop();
-                    smpl_cnt = 0;
+                    stop_dump();
                     break;
 
                 case 'R':