それのいど

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers solenoid.cpp Source File

solenoid.cpp

00001 #include "solenoid.h"
00002 
00003 Solenoid::Solenoid(PinName solenoiPin):sorenoidOutPut(solenoiPin)
00004 {
00005     kickperiod = DEFAULT_KICK_PERIOD;
00006     outputtime = DEFAULT_KICK_OUTPUT_TIME;
00007     timer.start();
00008     rhythm.start();
00009 }
00010 
00011 void Solenoid::setkickperiod(double kickperiod_)
00012 {
00013     kickperiod = kickperiod_;
00014 }
00015 
00016 void Solenoid::setoutputtime(double outputtime_)
00017 {
00018     outputtime = outputtime_;
00019 }
00020 
00021 void Solenoid::outPut()
00022 {
00023     now = timer.read();
00024     thread.start(callback(this, &Solenoid::assemble));
00025 }
00026 
00027 void Solenoid::assemble()
00028 {
00029     if(0.5 < outputtime) outputtime = 0.5;
00030     while(true) {
00031         if((now - lastkikkertime)> kickperiod) {
00032             lastkikkertime = now;
00033             rhythm.reset();
00034         }
00035         outputnowtime = rhythm.read();
00036         if(outputnowtime > outputtime) {
00037             sorenoidOutPut = 0;
00038         } else {
00039             sorenoidOutPut = 1;
00040         }
00041     }
00042 }
00043