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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MuscleWrite.cpp Source File

MuscleWrite.cpp

Go to the documentation of this file.
00001 /*!
00002  * @file MuscleWrite.cpp
00003  * @brief basic program for muscle controll with mbed/nucleo f446RE 
00004  * @author m.hdk <m.hdk816@gmail.com>
00005  * @date 2021
00006  */
00007 
00008 #include "mbed.h"
00009 #include "MuscleWrite.h"
00010 
00011 MuscleWrite::MuscleWrite(PinName pulse_pin,
00012                          float period,
00013                          float width)
00014     : pulse_pin_(pulse_pin), period_(period), width_(width)
00015 {
00016     out = false;
00017     pulse_pin_ = 0;
00018     period_ = period;
00019     width_ = width;
00020 }
00021 
00022 void MuscleWrite::enable()
00023 {
00024     over_cut_width();
00025     tic.attach(this, &MuscleWrite::rise, period_);
00026 }
00027 
00028 void MuscleWrite::disable()
00029 {
00030     tic.detach();
00031     pulse_pin_ = 0;
00032     out = false;
00033 }
00034 
00035 void MuscleWrite::rise()
00036 {
00037     if (out)
00038     {
00039         pulse_pin_ = 1;
00040         tim.attach(this, &MuscleWrite::fall, width_);
00041     }
00042 }
00043 
00044 void MuscleWrite::fall()
00045 {
00046     pulse_pin_ = 0;
00047 }
00048 int MuscleWrite::over_cut_width()
00049 {
00050     float max = 0.0f;
00051     max = (period_ / 2.0f);
00052     if (max < width_)
00053     {
00054         width_ = max;
00055         return 1;
00056     }
00057     else
00058     {
00059         return 0;
00060     }
00061 }
00062 
00063 void MuscleWrite::write(bool trg)
00064 {
00065     if (trg)
00066     {
00067         out = true;
00068     }
00069     else
00070     {
00071         out = false;
00072     }
00073 }