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: 2022_NHK_B_UK 2022_NHK_B_sub2
HOSOKIkikou.cpp
00001 00002 00003 #include "HOSOKIkikou.h" 00004 00005 00006 00007 HOSOKIkikou::HOSOKIkikou(ikarashiMDC *ik1, ikarashiMDC *ik2, ikarashiMDC *ik3, ikarashiMDC *ik4, uint8_t *b1, uint8_t *b2, uint8_t *b3, uint8_t *b4, int *env1, int *env2) : pc(USBTX,USBRX,115200){ 00008 init(ik1, ik2, ik3, ik4, b1, b2, b3, b4, env1, env2); 00009 } 00010 00011 void HOSOKIkikou::init(ikarashiMDC *ik1, ikarashiMDC *ik2, ikarashiMDC *ik3, ikarashiMDC *ik4, uint8_t *b1, uint8_t *b2, uint8_t *b3, uint8_t *b4, int *env1, int *env2){ 00012 ik[0] = ik1; //射出右 00013 ik[1] = ik2; //射出左 00014 ik[2] = ik3; //将校 00015 ik[3] = ik4; //装填 00016 button[0] = b1; //射出 00017 button[1] = b2; //上 00018 button[2] = b3; //下 00019 button[3] = b4; //装填 00020 encoder[0] = env1; //将校 00021 encoder[1] = env2; //装填 00022 for(int i=0; i<4; i++){ 00023 mspeed[i] = 0; 00024 if(i < 2) buff[i] = 0; 00025 } 00026 injecterFlag = false; 00027 } 00028 00029 void HOSOKIkikou::runAll(float speedIRight, float speedILeft, float speedLoad, float speedLift) 00030 { 00031 runInjection(speedIRight, speedILeft); 00032 runLoad(speedLoad); 00033 runLift(speedLift); 00034 for(int i=0; i<4; i++){ 00035 pc.printf("%f ",mspeed[i]); 00036 } 00037 pc.printf("\r\n"); 00038 } 00039 00040 void HOSOKIkikou::stopAll(){ 00041 //init(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 00042 for(int i=0; i<4; i++){ 00043 button[i] = NULL; 00044 mspeed[i] = 0; 00045 if(i < 3){ 00046 encoder[i] = NULL; 00047 } 00048 } 00049 injecterFlag = false; 00050 } 00051 00052 void HOSOKIkikou::runInjection(float speedRight, float speedLeft) 00053 { 00054 ik[0]->setSpeed(mspeed[0]); 00055 ik[1]->setSpeed(mspeed[1]); 00056 if(injecterFlag){ 00057 mspeed[0] = speedRight; 00058 mspeed[1] = speedLeft; 00059 }else{ 00060 mspeed[0] = 0; 00061 mspeed[1] = 0; 00062 } 00063 00064 buff[0] = *button[0] - buff[1]; 00065 buff[1] = *button[0]; 00066 00067 if(buff[0] <= 0 || button[0] == NULL){ 00068 return; 00069 }else{ 00070 injecterFlag = !injecterFlag; 00071 } 00072 } 00073 00074 void HOSOKIkikou::runLoad(float speed) 00075 { 00076 00077 ik[3]->setSpeed(mspeed[2]); 00078 if(*button[1] <= 0 && *button[2] <= 0 || button[1] == NULL || button[2] == NULL){ 00079 mspeed[2] = 0; 00080 return; 00081 }else if(*button[1] >= 1){ 00082 mspeed[2] = speed; 00083 }else if(*button[2] >= 1){ 00084 mspeed[2] = -speed; 00085 }else{ 00086 mspeed[2] = 0; 00087 } 00088 } 00089 00090 void HOSOKIkikou::runLift(float speed) 00091 { 00092 ik[2]->setSpeed(mspeed[3]); 00093 if(*button[3] <= 0){ 00094 mspeed[3] = 0; 00095 return; 00096 }else if(*button[3] >= 1 || button[3] == NULL){ 00097 mspeed[3] = speed; 00098 }else{ 00099 mspeed[3] = 0; 00100 } 00101 } 00102 00103 void HOSOKIkikou::checkAllMotorSpeed(float* data_buff){ 00104 data_buff = mspeed; 00105 }
Generated on Wed Oct 12 2022 09:05:53 by
1.7.2