This is a library for the electrical control of muscles. 筋肉に電気を流して制御して遊ぶためのライブラリ

Files at this revision

API Documentation at this revision

Comitter:
mhdk
Date:
Sun Jan 10 21:04:04 2021 +0000
Commit message:
init

Changed in this revision

MuscleWrite.cpp Show annotated file Show diff for this revision Revisions of this file
MuscleWrite.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MuscleWrite.cpp	Sun Jan 10 21:04:04 2021 +0000
@@ -0,0 +1,73 @@
+/*!
+ * @file MuscleWrite.cpp
+ * @brief basic program for muscle controll with mbed/nucleo f446RE 
+ * @author m.hdk <m.hdk816@gmail.com>
+ * @date 2021
+ */
+
+#include "mbed.h"
+#include "MuscleWrite.h"
+
+MuscleWrite::MuscleWrite(PinName pulse_pin,
+                         float period,
+                         float width)
+    : pulse_pin_(pulse_pin), period_(period), width_(width)
+{
+    out = false;
+    pulse_pin_ = 0;
+    period_ = period;
+    width_ = width;
+}
+
+void MuscleWrite::enable()
+{
+    over_cut_width();
+    tic.attach(this, &MuscleWrite::rise, period_);
+}
+
+void MuscleWrite::disable()
+{
+    tic.detach();
+    pulse_pin_ = 0;
+    out = false;
+}
+
+void MuscleWrite::rise()
+{
+    if (out)
+    {
+        pulse_pin_ = 1;
+        tim.attach(this, &MuscleWrite::fall, width_);
+    }
+}
+
+void MuscleWrite::fall()
+{
+    pulse_pin_ = 0;
+}
+int MuscleWrite::over_cut_width()
+{
+    float max = 0.0f;
+    max = (period_ / 2.0f);
+    if (max < width_)
+    {
+        width_ = max;
+        return 1;
+    }
+    else
+    {
+        return 0;
+    }
+}
+
+void MuscleWrite::write(bool trg)
+{
+    if (trg)
+    {
+        out = true;
+    }
+    else
+    {
+        out = false;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MuscleWrite.h	Sun Jan 10 21:04:04 2021 +0000
@@ -0,0 +1,33 @@
+/*!
+ * @file MuscleWrite.h
+ * @brief basic program for muscle controll with mbed/nucleo f446RE 
+ * @author m.hdk <m.hdk816@gmail.com>
+ * @date 2021
+ */
+
+#ifndef MuscleWrite_H
+#define MuscleWrite_H
+
+#include "mbed.h"
+
+class MuscleWrite
+{
+public:
+    MuscleWrite(PinName pulse_pin, float period = 0.025, float width = 0.002);
+    void enable();
+    void disable();
+    void write(bool s);
+
+private:
+    Timeout tim;
+    Ticker tic;
+    DigitalOut pulse_pin_;
+    float period_;
+    float width_;
+    bool out;
+    int over_cut_width();
+    void rise();
+    void fall();
+};
+
+#endif
\ No newline at end of file