mecha

Dependents:   2019NHK_A_manual_red 2019NHK_A_manual_red 2019NHK_A_manual_blue

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers towelest.cpp Source File

towelest.cpp

00001 #include "towelest.h"               //manual mode
00002 
00003 towelest::towelest(Serial* RS485,int address,PinName Limit0):
00004 pid(7.0, 0, 0, 0.01),
00005 LimitSW0(Limit0)
00006 {
00007     Motor = new ikarashiMDC*[2];
00008     Motor[0] = new ikarashiMDC(address,0,SM,RS485);
00009     Motor[1] = new ikarashiMDC(address,1,SM,RS485);     
00010       
00011     Motor[0]->braking = true;
00012     Motor[1]->braking = true;
00013     
00014     pid.setInputLimits(-6000, 6000);
00015     pid.setOutputLimits(-0.6,0.6);
00016     pid.setBias(0.0);
00017     pid.setMode(AUTO_MODE);
00018     pid.setSetPoint(0);
00019 
00020 }
00021 
00022 void towelest::open()
00023 {
00024     if(LimitSW0.read() == 1){
00025         Motor[0]->setSpeed(0);
00026     }else{
00027         Motor[0]->setSpeed(-0.2);
00028     }
00029 }
00030 
00031 void towelest::close()
00032 {
00033     Motor[0]->setSpeed(0.2);
00034 }
00035 
00036 void towelest::setPoint(int target)
00037 {
00038     pid.setSetPoint(target);
00039 }
00040 
00041 void towelest::setPulse(int Loli)
00042 {
00043     loli = Loli;
00044 }
00045 
00046 void towelest::pid_compute()
00047 {
00048     pid.setProcessValue(loli);
00049     compute = pid.compute();
00050     Motor[1]->setSpeed(compute);
00051         //pc.printf("%d  %d  %f \n\r",Limit1,Limit2,Limit3,RotationDistance);
00052 }
00053 
00054 void towelest::allstop()
00055 {
00056     Motor[0]->setSpeed(0);
00057 //    Motor[1]->setSpeed(0);
00058 }
00059