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.
jmStepperAxis.c
00001 /************************************************************************* 00002 * @file jmStepperAxis.c 00003 * @brief Command Line Interface StepperAxis Module 00004 * 00005 * @version 1.0 00006 * @date Feb 12, 2011 00007 */ 00008 00009 #include "jmMessages.h" 00010 #include "jmStepperAxis.h" 00011 #include "LPC17xx.h" 00012 #include "main.h" 00013 #include "jmCommands.h" 00014 #include "jmMessages.h" 00015 #include "jmRingBuffer.h" 00016 #include "stdio.h" 00017 #include "jmSwitch.h" 00018 #include "jmStepper.h" 00019 00020 #ifndef nonStop 00021 #define nonStop 65535 00022 #endif 00023 00024 #define NotInit 0 00025 #define Initialized 1 00026 #define CW 1 00027 #define CCW 0 00028 #define Open 1 00029 #define Close 0 00030 #define bothLimitSwitchActivated 4 00031 #define LimitCWReached 3 00032 #define LimitCCWReached 2 00033 #define LogicOK 1 00034 #define true 1 00035 #define false 0 00036 00037 // static structures creation 00038 struct StructStepperAxis sStepperAxis[stepperAxisQty]; 00039 00040 /** Module Data Structure Initialization 00041 * @brief All State Machines put to sleep. 00042 * @param[in] none 00043 * @returns none 00044 */ 00045 void StepperAxisInit(void){ 00046 int i; 00047 for(i=0;i<stepperAxisQty;i++){ 00048 sStepperAxis[i].active = false; 00049 } 00050 } 00051 00052 /** @brief stepperAxis Command Line Interface. 00053 * Set up a stepper axis from one stepper and two limit switch modules 00054 * Command Line Format: stepperAxis id stepperID limitCWid limitCCWid 00055 * @param[in] Extracted from command line id stepperID limitCWid limitCCWid 00056 * @returns Message: GPPSTA id stepperID limitCWid limitCCWid status 00057 */ 00058 void cli_StepperAxis(void){ 00059 unsigned int id, stepperID, limitCWid, limitCCWid; 00060 00061 if(ExtractUInteger(pLine,&id,0,stepperAxisQty-1)){ // extract stepper axis id 00062 if(ExtractUInteger(pLine,&stepperID,0,stepperQty-1)){ // extract stepper id 00063 if(ExtractUInteger(pLine,&limitCWid,0,switchQty-1)){ // extract Limit Switch CW id 00064 if(ExtractUInteger(pLine,&limitCCWid,0,switchQty-1)){ // extract Limit Switch CCW id 00065 00066 sStepperAxis[id].active=true; 00067 sStepperAxis[id].stepperID=stepperID; 00068 sStepperAxis[id].limitCW=limitCWid; 00069 sStepperAxis[id].limitCCW=limitCCWid; 00070 00071 // chip report to GUI 00072 rGPPSTA(id); 00073 if(Feedback)printf("StepperAxis %d StepperID %d limitCCWid %d limitCWid %d\n",id,stepperID,limitCCWid,limitCWid); 00074 return; 00075 }// CCW 00076 }// CW 00077 }// stepper 00078 }// axis 00079 if(Help)printf("stepperAxis (Stepper id)0..3 (limit switch CCW id)0..7 (limit switch CW id)0..7\n"); 00080 // Ignore pending command line 00081 NextCommand(nl,pLine); 00082 } 00083 00084 /** @brief 00085 * @param[in] none 00086 * @returns 00087 */ 00088 void StepperAxisSM(void) 00089 { 00090 int i; 00091 for(i=0;i<stepperAxisQty;i++) 00092 { 00093 if(sStepperAxis[i].active==true) 00094 { 00095 uint8_t oldStatus = sStepperAxis[i].status; 00096 00097 // Limits Reached 00098 // two limits switches activated ? 00099 if(sSwitch[sStepperAxis[i].limitCW].state == Close && sSwitch[sStepperAxis[i].limitCCW].state==Close){ 00100 sStepper[sStepperAxis[i].stepperID].nSteps=0; // stop stepper 00101 sStepperAxis[i].status = bothLimitSwitchActivated; 00102 if(oldStatus != bothLimitSwitchActivated)rGPPSTA(i); // report change 00103 continue; 00104 } 00105 // Limit Switch CW activated and step direction CW 00106 if(sSwitch[sStepperAxis[i].limitCW].state == Close && sStepper[sStepperAxis[i].stepperID].cw ==CW){ 00107 sStepper[sStepperAxis[i].stepperID].nSteps=0; // stop stepper 00108 sStepperAxis[i].status = LimitCWReached; 00109 if(oldStatus != LimitCWReached)rGPPSTA(i); // report change 00110 continue; 00111 } 00112 00113 // Limit Switch CCW activated and step direction CCW 00114 if(sSwitch[sStepperAxis[i].limitCCW].state == Close && sStepper[sStepperAxis[i].stepperID].cw ==CCW){ 00115 sStepper[sStepperAxis[i].stepperID].nSteps=0; // stop stepper 00116 sStepperAxis[i].status = LimitCCWReached; 00117 if(oldStatus != LimitCCWReached)rGPPSTA(i); // report change 00118 continue; 00119 } 00120 00121 // safe operating area 00122 // no limit switch activated 00123 if(sSwitch[sStepperAxis[i].limitCW].state == Open && sSwitch[sStepperAxis[i].limitCCW].state == Open){ 00124 sStepperAxis[i].status = LogicOK; 00125 if(oldStatus != LogicOK)rGPPSTA(i); // report change 00126 continue; 00127 } 00128 00129 // Limit Switch CW activated and step direction CCW 00130 if(sSwitch[sStepperAxis[i].limitCW].state == Close && sStepper[sStepperAxis[i].stepperID].cw ==CCW){ 00131 sStepperAxis[i].status = LogicOK; 00132 if(oldStatus != LogicOK)rGPPSTA(i); // report change 00133 continue; 00134 } 00135 00136 // Limit Switch CCW activated and step direction CW 00137 if(sSwitch[sStepperAxis[i].limitCCW].state == Close && sStepper[sStepperAxis[i].stepperID].cw ==CW){ 00138 sStepperAxis[i].status = LogicOK; 00139 if(oldStatus != LogicOK)rGPPSTA(i); // report change 00140 continue; 00141 } 00142 } 00143 } 00144 } 00145 00146 /** Module Get Module Process Properties Command Line Interface 00147 * @brief Command Line Interface to Get Module Public Process Properties 00148 * @param[in] id Extracted from command line id Process identification 00149 * @returns none 00150 */ 00151 void cli_GPPSTA(void) 00152 { unsigned int id; 00153 if(ExtractUInteger(pLine,&id,0,stepperAxisQty-1)){ // extract id 00154 rGPPSTA(id); 00155 return; 00156 } 00157 00158 if(Help)printf("GPPSTA (StepperAxis id)0..%d\n",stepperAxisQty-1); 00159 // Ignore pending command line 00160 NextCommand(nl,pLine); 00161 } 00162 00163 /** Public Properties Message 00164 * @brief Send Process Properties to update GUI 00165 * @param[in] id Process identification 00166 * @returns Message: GPPSTA id stepperID limitCWid limitCCWid status 00167 */ 00168 void rGPPSTA(unsigned int id ){ 00169 int status; 00170 if(sStepperAxis[id].active==false)status=0; 00171 else status = sStepperAxis[id].status; 00172 printf("GPPSTA %d %d %d %d %d\n",id,sStepperAxis[id].stepperID,sStepperAxis[id].limitCCW,sStepperAxis[id].limitCW ,status); 00173 }
Generated on Sat Jul 16 2022 00:01:14 by
1.7.2