足回り動かすためのライブラリ

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers motor.cpp Source File

motor.cpp

00001 #include "motor.hpp"
00002 
00003 Motor::Motor(PinName plus,PinName minus,int period,int id):ID(id){
00004     Plus = new PwmOut(plus);
00005     Minus = new PwmOut(minus);
00006     Plus->period_us(period);
00007     Minus->period_us(period);
00008 }
00009 Motor::~Motor(){}
00010 
00011 void Motor::setLimit(double max,double min){
00012     Max = max;
00013     Min = min;
00014 }
00015 
00016 void Motor::setPWM(double pwm){
00017     if(pwm >= Max)      Pwm=Max;
00018     else if(pwm<=Min)   Pwm=Min;
00019     else                Pwm=pwm;
00020     if(Pwm<0.0){
00021         *Plus=0.0;
00022         *Minus=Pwm*-1;
00023     }
00024     else{
00025         *Minus=0.0;
00026         *Plus=Pwm;
00027     }
00028 }
00029 
00030 double Motor::get_ID() {return ID;}