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.
Dependents: Nucleo_Motor Nucleo_Motor
Revision 0:0d2b4508badd, committed 2015-09-23
- Comitter:
- kikoaac
- Date:
- Wed Sep 23 06:00:24 2015 +0000
- Commit message:
- ??Class
;
Changed in this revision
fusion_Motor.cpp | Show annotated file Show diff for this revision Revisions of this file |
fusion_Motor.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 0d2b4508badd fusion_Motor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fusion_Motor.cpp Wed Sep 23 06:00:24 2015 +0000 @@ -0,0 +1,87 @@ +/** + * Includes + */ +#include "fusion_Motor.h" + + +fusion_Motor::fusion_Motor( QEI &p, PID &q, Motor &m): QEI(p),PID(q),Motor(m) +{ + flag=0; + QEI::state(1); + interval=0.3; + Maxrpm=100.0F; + Minrpm=-100.0F; + Max=1; + max=1; + Min=-1; + min=-1; + mode = Normal; + OutputLimits(1,-1); +} +void fusion_Motor::setup(Mode _mode) +{ + setmode(_mode); +} +void fusion_Motor::InterruptAction() +{ + //printf("%f\r\n",data); + Motor::run(Free,data); + switch(mode) + { + case Normal: + inter.detach(); + break; + case Servo: + dPoint=getSumangle(); + PIDctrl(); + break; + case Speed: + RPM = dPoint=getRPM(); + PIDctrl(); + break; + } + Motor::operator=(data); +} +void fusion_Motor::start(float target) +{ + dTarget=target; + inter.attach(this,&fusion_Motor::InterruptAction,fusion_Motor::interval); +} +void fusion_Motor::start() +{ + inter.attach(this,&fusion_Motor::InterruptAction,fusion_Motor::interval); +} +void fusion_Motor::motor_run(float actionNum) +{ + switch(mode) + { + case Normal: + Nomalrun(actionNum); + break; + case Servo: + Servorun(actionNum); + break; + case Speed: + Speedrun(flag?rerpmper(actionNum):rpmper(actionNum)); + break; + } +} + +float fusion_Motor::rpmper(float rpm) +{ + if(rpm>Maxrpm)rpm=Maxrpm; + else if(rpm<Minrpm)rpm=Minrpm; + return rpm; +} +float fusion_Motor::rerpmper(float rpm) +{ + if(rpm>Max)rpm=Max; + else if(rpm<Min)rpm=Min; + return rpmper(rpm*Maxrpm); +} + + + + + +
diff -r 000000000000 -r 0d2b4508badd fusion_Motor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fusion_Motor.h Wed Sep 23 06:00:24 2015 +0000 @@ -0,0 +1,77 @@ + +#include "mbed.h" +#include "Motor.h" +#include "PID.h" +#include "QEI.h" +#ifndef fusion_Motor_H +#define fusion_Motor_H + +class fusion_Motor : public QEI ,public PID ,public Motor +{ + + Ticker inter; +protected: + fusion_Motor& operator=(const fusion_Motor &q) { + + return *this; + } +public: + fusion_Motor( QEI &p, PID &q,Motor &m) ; + float interval; + typedef enum Mode { + Normal, + Servo, + Speed + + } Mode; + float getrpm() + { + return RPM; + } + /*fusion_Motor() : PID(),QEI(),Motor() + { + printf("defoult con\r\n"); + }*/ + + void setup(Mode _mode); + void setmode(Mode _mode){mode=_mode;} + void motor_run(float actionNum); + fusion_Motor& operator() (Mode _mode,bool f) + { + + flag=f; + setmode(_mode); + pid_reset(); + return *this; + } + fusion_Motor& operator= (float actnum) + { + motor_run(actnum); + return *this; + } + void start(float target); + void start(); + void write(float tar); + + + + void maxrpm(float rpm){Maxrpm = rpm;} + void minrpm(float rpm){Minrpm = rpm;} + float rpmper(float rpm); + float rerpmper(float rpm); + void Nomalrun(float duty){Motor::operator=(duty);} + void Servorun(float angle){dTarget = angle;} + void Speedrun(float rpm){dTarget = rpm;} + +private: + float RPM; + bool flag; + void InterruptAction(); + Mode mode; + float Max,Min; + float Maxrpm; + float Minrpm; +}; + +#endif +