Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Motor.cpp
00001 #include "Motor.h" 00002 00003 Motor::Motor(PinName pwm, float _period/*, float* linCoef, float lowerSat, float upperSat*/) : PwmOut(pwm) 00004 { 00005 //period(_period); 00006 period_us(_period); 00007 00008 currentPower = 0; 00009 00010 //setPower(currentPower); 00011 00012 //this->linCoef = linCoef; 00013 00014 //this->lowerSat = lowerSat; 00015 //this->upperSat = upperSat; 00016 } 00017 00018 /*Motor::Motor(PinName pwm, float periodms) : PwmOut(pwm) 00019 { 00020 //Motor(pwm, (periodms*1000), new float[1], 0, 100); 00021 period_ms(periodms); 00022 00023 //currentPower = 0; 00024 00025 //this->linCoef = new float[1]; 00026 00027 //this->lowerSat = 0; 00028 //this->upperSat = 100; 00029 }*/ 00030 00031 void Motor::setPower(float power) 00032 { 00033 power = clampFloat(power, 0.0, 100.0); 00034 00035 //pulsewidth(PWM_MIN + (power / 100.0) * PWM_DT); 00036 write( (100-(PWM_MIN + power))/100); 00037 currentPower = power; 00038 } 00039 00040 void Motor::setPowerLin(float power) 00041 { 00042 setPower(power); 00043 /* 00044 float pwm = 0; 00045 00046 power = clampFloat(power, 0.0, 100.0); 00047 00048 for (int i = 0; i < 5; i++) 00049 { 00050 pwm += linCoef[4-i] * pow(power/100.0, i); 00051 } 00052 00053 setPower(lowerSat + pwm*(upperSat - lowerSat)); 00054 */ 00055 } 00056 void Motor::arm(int pwm_ms) 00057 { 00058 pulsewidth_ms(pwm_ms); 00059 //write( (power)/100 ); 00060 } 00061 void Motor::accumulatePower(float accPower) 00062 { 00063 setPower(currentPower + accPower); 00064 } 00065 00066 float Motor::getPower() 00067 { 00068 return currentPower; 00069 }
Generated on Tue Jul 19 2022 01:26:58 by
1.7.2