Basic Mid-Level control for the rebuilt MorphGI control unit, using PWM to communicate with the low level controllers.

Dependencies:   ros_lib_kinetic

Committer:
WD40andTape
Date:
Wed Aug 29 10:47:02 2018 +0000
Revision:
13:a373dfc57b89
Parent:
12:595ed862e52f
Child:
14:54c3759e76ed
Added limits to smooth path plan and fixed path replan (isTimeChanged) logic.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WD40andTape 7:5b6a2cefbf3b 1 // STANDARD IMPORTS
WD40andTape 7:5b6a2cefbf3b 2 #include "math.h"
WD40andTape 7:5b6a2cefbf3b 3 // MBED IMPORTS
dofydoink 0:607bc887b6e0 4 #include "mbed.h"
WD40andTape 6:f0a18e28a322 5 #include "mbed_events.h"
WD40andTape 7:5b6a2cefbf3b 6 // CUSTOM IMPORTS
dofydoink 12:595ed862e52f 7 #include "MLSettings.h"
WD40andTape 7:5b6a2cefbf3b 8 #include "HLComms.h"
WD40andTape 8:d6657767a182 9 #include "LLComms.h"
dofydoink 0:607bc887b6e0 10
WD40andTape 13:a373dfc57b89 11 //DigitalOut pinTesty(PB_8);
WD40andTape 13:a373dfc57b89 12
dofydoink 12:595ed862e52f 13 // Maximum achievable mm path tolerance plus additional % tolerance
dofydoink 12:595ed862e52f 14 const float FLT_PATH_TOLERANCE = MAX_SPEED_MMPS * PATH_SAMPLE_TIME_S * (1.0f+FLT_PERCENT_PATH_TOLERANCE);
dofydoink 0:607bc887b6e0 15
WD40andTape 7:5b6a2cefbf3b 16 // PATH VARIABLES
WD40andTape 7:5b6a2cefbf3b 17 double dblVelocity_mmps[N_CHANNELS] = { 0.0 }; // The linear path velocity (not sent to actuator)
WD40andTape 7:5b6a2cefbf3b 18 double dblLinearPathCurrentPos_mm[N_CHANNELS]={ 0.0 }; // The current position of the linear path (not sent to actuator)
WD40andTape 7:5b6a2cefbf3b 19 double dblTargetActPos_mm[N_CHANNELS] = { 0.0 }; // The final target position for the actuator
dofydoink 0:607bc887b6e0 20
dofydoink 12:595ed862e52f 21 // These have to be declared in the global scope or we get a stack overflow. No idea why.
dofydoink 11:7029367a1840 22 double _dblVelocity_mmps[N_CHANNELS];
dofydoink 12:595ed862e52f 23 //double _dblLinearPathCurrentPos_mm[N_CHANNELS];
dofydoink 12:595ed862e52f 24 double dblADCCurrentPosition[N_CHANNELS];
dofydoink 11:7029367a1840 25
WD40andTape 7:5b6a2cefbf3b 26 Serial pc(USBTX, USBRX); // tx, rx for usb debugging
dofydoink 12:595ed862e52f 27 LLComms llcomms;
WD40andTape 3:c83291bf9fd2 28
WD40andTape 10:1b6daba32452 29 Thread threadLowLevelSPI(osPriorityRealtime);
WD40andTape 13:a373dfc57b89 30 Thread threadSmoothPathPlan(osPriorityNormal);
WD40andTape 4:303584310071 31 Thread threadReceiveAndReplan(osPriorityBelowNormal);
dofydoink 0:607bc887b6e0 32
WD40andTape 4:303584310071 33 Mutex mutPathIn;
WD40andTape 7:5b6a2cefbf3b 34 Semaphore semPathPlan(1);
dofydoink 0:607bc887b6e0 35
WD40andTape 7:5b6a2cefbf3b 36 Timer timer;
WD40andTape 7:5b6a2cefbf3b 37 Ticker PathCalculationTicker;
dofydoink 0:607bc887b6e0 38
WD40andTape 7:5b6a2cefbf3b 39 void startPathPlan() { // Plan a new linear path after receiving new target data
WD40andTape 4:303584310071 40 semPathPlan.release(); // Uses threadReceiveAndReplan which is below normal priority to ensure consistent transmission to LL
dofydoink 0:607bc887b6e0 41 }
dofydoink 0:607bc887b6e0 42
WD40andTape 7:5b6a2cefbf3b 43 // This function will be called when a new transmission is received from high level
WD40andTape 7:5b6a2cefbf3b 44 void ReceiveAndReplan() {
WD40andTape 7:5b6a2cefbf3b 45 HLComms hlcomms(SERVER_PORT);
WD40andTape 6:f0a18e28a322 46
WD40andTape 6:f0a18e28a322 47 int error_code;
WD40andTape 7:5b6a2cefbf3b 48 error_code = hlcomms.setup_server();
WD40andTape 6:f0a18e28a322 49 if( error_code == -1 ) return;
WD40andTape 7:5b6a2cefbf3b 50 error_code = hlcomms.accept_connection();
WD40andTape 7:5b6a2cefbf3b 51 if( error_code == -1 ) {
WD40andTape 7:5b6a2cefbf3b 52 hlcomms.close_server();
WD40andTape 7:5b6a2cefbf3b 53 return;
WD40andTape 7:5b6a2cefbf3b 54 }
WD40andTape 6:f0a18e28a322 55
WD40andTape 7:5b6a2cefbf3b 56 int ii;
WD40andTape 7:5b6a2cefbf3b 57 struct msg_format input; //hlcomms.msg_format
WD40andTape 4:303584310071 58
WD40andTape 6:f0a18e28a322 59 while( true ) {
WD40andTape 6:f0a18e28a322 60 // RECEIVE MESSAGE
WD40andTape 9:cd3607ba5643 61 error_code = hlcomms.receive_message();
WD40andTape 6:f0a18e28a322 62 if( error_code == NSAPI_ERROR_NO_CONNECTION ) { // -3004
dofydoink 12:595ed862e52f 63 if(IS_PRINT_OUTPUT) printf("Client disconnected.\n\r");
WD40andTape 7:5b6a2cefbf3b 64 hlcomms.close_server();
WD40andTape 6:f0a18e28a322 65 return;
WD40andTape 6:f0a18e28a322 66 } else if( error_code < 0 ) {
dofydoink 12:595ed862e52f 67 if(IS_PRINT_OUTPUT) printf("Error %i. Could not send data over the TCP socket. "
WD40andTape 6:f0a18e28a322 68 "Perhaps the server socket is not connected to a remote host? "
WD40andTape 6:f0a18e28a322 69 "Or the socket is set to non-blocking or timed out?\n\r", error_code);
WD40andTape 7:5b6a2cefbf3b 70 hlcomms.close_server();
WD40andTape 6:f0a18e28a322 71 return;
WD40andTape 6:f0a18e28a322 72 }
WD40andTape 9:cd3607ba5643 73 input = hlcomms.process_message();
WD40andTape 1:2a43cf183a62 74
WD40andTape 7:5b6a2cefbf3b 75 // PROCESS INPUT
WD40andTape 7:5b6a2cefbf3b 76 double dblTargetChambLen_mm[N_CHANNELS]; // The currenly assigned final target position (actuator will reach this at end of path)
dofydoink 12:595ed862e52f 77 if(IS_PRINT_OUTPUT) printf("REPLAN, %f\r\n",input.duration);
WD40andTape 7:5b6a2cefbf3b 78 // Update front segment
dofydoink 11:7029367a1840 79 /*dblTargetChambLen_mm[0] = input.psi[0][0]*1000;
WD40andTape 6:f0a18e28a322 80 dblTargetChambLen_mm[1] = input.psi[0][1]*1000;
WD40andTape 6:f0a18e28a322 81 dblTargetChambLen_mm[2] = input.psi[0][2]*1000;
WD40andTape 7:5b6a2cefbf3b 82 // Update mid segment
WD40andTape 6:f0a18e28a322 83 dblTargetChambLen_mm[6] = input.psi[1][0]*1000;
WD40andTape 7:5b6a2cefbf3b 84 dblTargetChambLen_mm[7] = dblTargetChambLen_mm[6]; // Same because two pumps are used
WD40andTape 7:5b6a2cefbf3b 85 // Update rear segment
WD40andTape 6:f0a18e28a322 86 dblTargetChambLen_mm[3] = input.psi[2][0]*1000;
WD40andTape 6:f0a18e28a322 87 dblTargetChambLen_mm[4] = input.psi[2][1]*1000;
dofydoink 11:7029367a1840 88 dblTargetChambLen_mm[5] = input.psi[2][2]*1000;*/
dofydoink 11:7029367a1840 89 dblTargetChambLen_mm[3] = input.psi[0][0]*1000;
dofydoink 11:7029367a1840 90 dblTargetChambLen_mm[4] = input.psi[0][1]*1000;
dofydoink 11:7029367a1840 91 dblTargetChambLen_mm[5] = input.psi[0][2]*1000;
dofydoink 11:7029367a1840 92 // Update mid segment
dofydoink 11:7029367a1840 93 dblTargetChambLen_mm[6] = input.psi[1][0]*1000;
dofydoink 11:7029367a1840 94 dblTargetChambLen_mm[7] = dblTargetChambLen_mm[6]; // Same because two pumps are used
dofydoink 11:7029367a1840 95 // Update rear segment
dofydoink 11:7029367a1840 96 dblTargetChambLen_mm[0] = input.psi[2][0]*1000;
dofydoink 11:7029367a1840 97 dblTargetChambLen_mm[1] = input.psi[2][1]*1000;
dofydoink 11:7029367a1840 98 dblTargetChambLen_mm[2] = input.psi[2][2]*1000;
dofydoink 11:7029367a1840 99
dofydoink 11:7029367a1840 100 mutPathIn.lock(); // Lock variables to avoid race condition
dofydoink 12:595ed862e52f 101 /*for(int j = 0; j<N_CHANNELS; j++) {
dofydoink 11:7029367a1840 102 //_dblVelocity_mmps[j] = dblVelocity_mmps[j];
dofydoink 11:7029367a1840 103 _dblLinearPathCurrentPos_mm[j] = dblLinearPathCurrentPos_mm[j];
dofydoink 12:595ed862e52f 104 }*/
dofydoink 12:595ed862e52f 105 for(int j = 0; j<N_CHANNELS; j++) {
dofydoink 12:595ed862e52f 106 dblADCCurrentPosition[j] = dblLinearPathCurrentPos_mm[j];
dofydoink 12:595ed862e52f 107 //dblADCCurrentPosition[j] = llcomms.ReadADCPosition_mtrs(j); // Read position from channel
dofydoink 11:7029367a1840 108 }
dofydoink 12:595ed862e52f 109
dofydoink 11:7029367a1840 110 mutPathIn.unlock(); // Unlock mutex
dofydoink 0:607bc887b6e0 111
WD40andTape 13:a373dfc57b89 112 //bool isTimeChanged = 0;
WD40andTape 6:f0a18e28a322 113 double dblMaxRecalculatedTime = input.duration;
WD40andTape 13:a373dfc57b89 114 // Convert from requested chamber to actuator space and limit actuator positions
WD40andTape 4:303584310071 115 for (ii = 0; ii< N_CHANNELS; ii++) {
WD40andTape 13:a373dfc57b89 116 // If sent a negative requested position, do NOT replan that actuator
WD40andTape 13:a373dfc57b89 117 //if( dblTargetChambLen_mm[ii] < 0.0 ) continue;
dofydoink 0:607bc887b6e0 118 //check to see if positions are achievable
dofydoink 12:595ed862e52f 119 dblTargetActPos_mm[ii] = dblTargetChambLen_mm[ii]*FLT_ACTUATOR_CONVERSION[ii];
WD40andTape 13:a373dfc57b89 120 dblTargetActPos_mm[ii] = min( max( 0.0 , dblTargetActPos_mm[ii] ) , 25.0 );
WD40andTape 6:f0a18e28a322 121 //!! LIMIT CHAMBER LENGTHS TOO
WD40andTape 6:f0a18e28a322 122 }
WD40andTape 13:a373dfc57b89 123 // Calculate achievable velocities, and hence time, for the requested move to complete within tolerance
WD40andTape 6:f0a18e28a322 124 double dblActPosChange;
WD40andTape 6:f0a18e28a322 125 short sgn;
WD40andTape 7:5b6a2cefbf3b 126 for (ii = 0; ii< N_CHANNELS; ii++) { // Work out new velocities
WD40andTape 13:a373dfc57b89 127 // If sent a negative requested position, do NOT replan that actuator
WD40andTape 13:a373dfc57b89 128 //if( dblTargetChambLen_mm[ii] < 0.0 ) continue;
WD40andTape 13:a373dfc57b89 129
dofydoink 11:7029367a1840 130 /*dblActPosChange = 1.0; // or = 0.0;
dofydoink 11:7029367a1840 131 _dblVelocity_mmps[ii] = 0.0;*/ // DOESN'T CRASH
dofydoink 11:7029367a1840 132 /*dblActPosChange = dblTargetActPos_mm[ii];
dofydoink 11:7029367a1840 133 _dblVelocity_mmps[ii] = 0.0;*/ // DOESN'T CRASH
dofydoink 11:7029367a1840 134 /*dblActPosChange = _dblLinearPathCurrentPos_mm[ii];*/ // DOESN'T CRASH
dofydoink 11:7029367a1840 135 /*_dblVelocity_mmps[ii] = _dblLinearPathCurrentPos_mm[ii];*/ // DOESN'T CRASH
dofydoink 11:7029367a1840 136 /*dblActPosChange = 0.0;
dofydoink 11:7029367a1840 137 _dblVelocity_mmps[ii] = _dblLinearPathCurrentPos_mm[ii];*/ // DOESN'T CRASH
dofydoink 11:7029367a1840 138
dofydoink 11:7029367a1840 139 // DOES CRASH but not with a return at the end of while OR if _ variables are declared globally
dofydoink 11:7029367a1840 140 /*dblActPosChange = _dblLinearPathCurrentPos_mm[ii];
dofydoink 11:7029367a1840 141 _dblVelocity_mmps[ii] = 0.0;*/
dofydoink 11:7029367a1840 142
dofydoink 12:595ed862e52f 143 dblActPosChange = dblTargetActPos_mm[ii] - dblADCCurrentPosition[ii];
WD40andTape 13:a373dfc57b89 144 if( fabs(dblActPosChange) < FLT_PATH_TOLERANCE ) { // If actuator ii is already within tolerance
WD40andTape 6:f0a18e28a322 145 dblActPosChange = 0.0;
WD40andTape 13:a373dfc57b89 146 //isTimeChanged = 1;
dofydoink 0:607bc887b6e0 147 }
dofydoink 11:7029367a1840 148 //IS BELOW
WD40andTape 13:a373dfc57b89 149 if( input.duration < 0.000000001 ) { // If max (safe) velocity was requested
WD40andTape 6:f0a18e28a322 150 sgn = (dblActPosChange > 0) ? 1 : ((dblActPosChange < 0) ? -1 : 0);
dofydoink 11:7029367a1840 151 _dblVelocity_mmps[ii] = sgn * MAX_SPEED_MMPS;
WD40andTape 13:a373dfc57b89 152 //isTimeChanged = 1;
WD40andTape 6:f0a18e28a322 153 } else {
dofydoink 11:7029367a1840 154 _dblVelocity_mmps[ii] = dblActPosChange / input.duration;
WD40andTape 6:f0a18e28a322 155 }
dofydoink 11:7029367a1840 156 //IS ABOVE
WD40andTape 13:a373dfc57b89 157 // Check to see if velocities are achievable -- this can move into the else section of the above if statement
dofydoink 11:7029367a1840 158 if(abs(_dblVelocity_mmps[ii]) > MAX_SPEED_MMPS) {
dofydoink 11:7029367a1840 159 if(_dblVelocity_mmps[ii]>0) {
dofydoink 11:7029367a1840 160 _dblVelocity_mmps[ii] = MAX_SPEED_MMPS;
WD40andTape 6:f0a18e28a322 161 } else {
dofydoink 11:7029367a1840 162 _dblVelocity_mmps[ii] = -1*MAX_SPEED_MMPS;
WD40andTape 6:f0a18e28a322 163 }
WD40andTape 13:a373dfc57b89 164 //isTimeChanged = 1;
WD40andTape 6:f0a18e28a322 165 }
WD40andTape 13:a373dfc57b89 166 // Recalculate the move's time after altering the position and/or velocity
WD40andTape 6:f0a18e28a322 167 double dblRecalculatedTime;
dofydoink 11:7029367a1840 168 if( fabs(_dblVelocity_mmps[ii]) < 0.000000001 ) {
WD40andTape 6:f0a18e28a322 169 dblRecalculatedTime = 0;
WD40andTape 6:f0a18e28a322 170 } else {
dofydoink 11:7029367a1840 171 dblRecalculatedTime = dblActPosChange / _dblVelocity_mmps[ii];
WD40andTape 6:f0a18e28a322 172 }
WD40andTape 13:a373dfc57b89 173 // Find the maximum time for any actuator's move for synchronization
WD40andTape 6:f0a18e28a322 174 if( dblRecalculatedTime > dblMaxRecalculatedTime ) {
WD40andTape 6:f0a18e28a322 175 dblMaxRecalculatedTime = dblRecalculatedTime;
WD40andTape 6:f0a18e28a322 176 }
WD40andTape 6:f0a18e28a322 177 }
WD40andTape 13:a373dfc57b89 178 // Finally recalculate all of the velocities based upon this maximum time for synchronization
WD40andTape 13:a373dfc57b89 179 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!MUTEX FOR dblVelocity_mmps and dblTargetActPos_mm??
WD40andTape 13:a373dfc57b89 180 //if( dblMaxRecalculatedTime >= 0.000000001 ) { // isTimeChanged &&
WD40andTape 13:a373dfc57b89 181 for (ii = 0; ii< N_CHANNELS; ii++) { // Work out new velocities
WD40andTape 13:a373dfc57b89 182 // If sent a negative requested position, do NOT replan that actuator
WD40andTape 13:a373dfc57b89 183 //if( dblTargetChambLen_mm[ii] < 0.0 ) continue;
WD40andTape 13:a373dfc57b89 184
WD40andTape 13:a373dfc57b89 185 _dblVelocity_mmps[ii] = (dblTargetActPos_mm[ii] - dblADCCurrentPosition[ii]) / dblMaxRecalculatedTime;
WD40andTape 13:a373dfc57b89 186 dblVelocity_mmps[ii] = _dblVelocity_mmps[ii];
WD40andTape 6:f0a18e28a322 187 }
WD40andTape 13:a373dfc57b89 188 // !!!!!!!!! IF TIME ISN'T CHANGED THEN VELOCITY ISN'T UPDATED.....................................................................................
WD40andTape 6:f0a18e28a322 189 // SEND MESSAGE
dofydoink 11:7029367a1840 190 //dblMaxRecalculatedTime = 1.0;
WD40andTape 9:cd3607ba5643 191 hlcomms.make_message(&dblMaxRecalculatedTime);
WD40andTape 9:cd3607ba5643 192 error_code = hlcomms.send_message();
WD40andTape 6:f0a18e28a322 193 if( error_code < 0 ) {
dofydoink 12:595ed862e52f 194 if(IS_PRINT_OUTPUT) printf("Error %i. Could not send data over the TCP socket. "
WD40andTape 6:f0a18e28a322 195 "Perhaps the server socket is not bound or not set to listen for connections? "
WD40andTape 6:f0a18e28a322 196 "Or the socket is set to non-blocking or timed out?\n\r", error_code);
WD40andTape 7:5b6a2cefbf3b 197 hlcomms.close_server();
WD40andTape 6:f0a18e28a322 198 return;
WD40andTape 6:f0a18e28a322 199 }
WD40andTape 6:f0a18e28a322 200 }
WD40andTape 6:f0a18e28a322 201
dofydoink 0:607bc887b6e0 202 }
dofydoink 0:607bc887b6e0 203
WD40andTape 4:303584310071 204 void CalculateSmoothPath() {
dofydoink 5:712e7634c779 205 int jj;
WD40andTape 1:2a43cf183a62 206 double dblMeasuredSampleTime;
WD40andTape 7:5b6a2cefbf3b 207 double dblSmoothPathCurrentPos_mm[N_CHANNELS] = { 0.0 }; // The current position of the smooth path (not sent to actuator)
WD40andTape 7:5b6a2cefbf3b 208 //double dblPosition_mtrs[N_CHANNELS]; // The actual chamber lengths in meters given as the change in length relative to neutral (should always be >=0)
WD40andTape 7:5b6a2cefbf3b 209 //double dblPressure_bar[N_CHANNELS]; // The pressure in a given chamber in bar (1 bar = 100,000 Pa)
WD40andTape 4:303584310071 210 while(1) {
dofydoink 0:607bc887b6e0 211 semPathPlan.wait();
WD40andTape 13:a373dfc57b89 212 //pinTesty = 1;
WD40andTape 1:2a43cf183a62 213 // If run time is more than 50 us from expected, calculate from measured time step
WD40andTape 4:303584310071 214 if (fabs(PATH_SAMPLE_TIME_S*1000000 - timer.read_us()) > 50) {
dofydoink 5:712e7634c779 215 dblMeasuredSampleTime = timer.read();
WD40andTape 4:303584310071 216 } else {
WD40andTape 1:2a43cf183a62 217 dblMeasuredSampleTime = PATH_SAMPLE_TIME_S;
WD40andTape 1:2a43cf183a62 218 }
WD40andTape 4:303584310071 219 timer.reset();
WD40andTape 1:2a43cf183a62 220
dofydoink 5:712e7634c779 221 for(jj = 0; jj < N_CHANNELS; jj++) {
WD40andTape 7:5b6a2cefbf3b 222 //dblPressure_bar[jj] = ReadADCPressure_bar(jj); // Read pressure from channel
WD40andTape 7:5b6a2cefbf3b 223 //dblPosition_mtrs[jj] = ReadADCPosition_mtrs(jj); // Read position from channel
WD40andTape 1:2a43cf183a62 224
WD40andTape 7:5b6a2cefbf3b 225 // Calculate next step in linear path
WD40andTape 7:5b6a2cefbf3b 226 mutPathIn.lock(); // Lock relevant mutex
WD40andTape 7:5b6a2cefbf3b 227 // Check tolerance
dofydoink 12:595ed862e52f 228 if (fabs(dblLinearPathCurrentPos_mm[jj] - dblTargetActPos_mm[jj]) <= FLT_PATH_TOLERANCE) {
WD40andTape 7:5b6a2cefbf3b 229 dblVelocity_mmps[jj] = 0.0; // Stop linear path generation when linear path is within tolerance of target position
WD40andTape 7:5b6a2cefbf3b 230 }
dofydoink 11:7029367a1840 231 dblLinearPathCurrentPos_mm[jj] = dblLinearPathCurrentPos_mm[jj] + dblVelocity_mmps[jj]*dblMeasuredSampleTime;
WD40andTape 13:a373dfc57b89 232 dblLinearPathCurrentPos_mm[jj] = min( max( 0.0 , dblLinearPathCurrentPos_mm[jj] ) , 25.0 );
WD40andTape 7:5b6a2cefbf3b 233 mutPathIn.unlock(); // Unlock relevant mutex
dofydoink 0:607bc887b6e0 234
WD40andTape 7:5b6a2cefbf3b 235 // Calculate next step in smooth path
dofydoink 12:595ed862e52f 236 dblSmoothPathCurrentPos_mm[jj] = FLT_SMOOTHING_FACTOR*dblLinearPathCurrentPos_mm[jj] + (1.0f-FLT_SMOOTHING_FACTOR)*dblSmoothPathCurrentPos_mm[jj];
dofydoink 11:7029367a1840 237 dblSmoothPathCurrentPos_mm[jj] = max( 0.0 , dblSmoothPathCurrentPos_mm[jj] );
dofydoink 11:7029367a1840 238 llcomms.mutChannel[jj].lock(); // MUTEX LOCK
WD40andTape 10:1b6daba32452 239 llcomms.demandPosition[jj] = (int) ((dblSmoothPathCurrentPos_mm[jj]/MAX_ACTUATOR_LENGTH)*8191);// Convert to a 13-bit number
WD40andTape 10:1b6daba32452 240 llcomms.demandPosition[jj] = llcomms.demandPosition[jj] & 0x1FFF; // Ensure number is 13-bit
WD40andTape 8:d6657767a182 241 llcomms.mutChannel[jj].unlock(); // MUTEX UNLOCK
dofydoink 0:607bc887b6e0 242
WD40andTape 10:1b6daba32452 243 llcomms.isDataReady[jj] = 1; // Signal that data ready
WD40andTape 4:303584310071 244 } // end for
WD40andTape 7:5b6a2cefbf3b 245
dofydoink 12:595ed862e52f 246 //if(IS_PRINT_OUTPUT) printf("%f, %d\r\n",dblSmoothPathCurrentPos_mm[0], intDemandPos_Tx[0]);
dofydoink 12:595ed862e52f 247 //if(IS_PRINT_OUTPUT) printf("%f, %f, %f, %f, %f, %f, %f, %f\r\n",dblLinearPathCurrentPos_mm[0],dblLinearPathCurrentPos_mm[1],dblLinearPathCurrentPos_mm[2],
dofydoink 11:7029367a1840 248 // dblLinearPathCurrentPos_mm[3],dblLinearPathCurrentPos_mm[4],dblLinearPathCurrentPos_mm[5],dblLinearPathCurrentPos_mm[6],dblLinearPathCurrentPos_mm[7]);
dofydoink 12:595ed862e52f 249 //if(IS_PRINT_OUTPUT) printf("%f\r\n",dblLinearPathCurrentPos_mm[0]);
WD40andTape 13:a373dfc57b89 250 //pinTesty = 0;
WD40andTape 4:303584310071 251 } // end while
WD40andTape 3:c83291bf9fd2 252 }
dofydoink 0:607bc887b6e0 253
WD40andTape 13:a373dfc57b89 254 int main() {
WD40andTape 7:5b6a2cefbf3b 255 pc.baud(BAUD_RATE);
WD40andTape 13:a373dfc57b89 256 printf("Sup bruvva! I'll be your mid-level controller for today.\r\n");
WD40andTape 13:a373dfc57b89 257 printf("Compiled at %s\r\n.",__TIME__);
dofydoink 5:712e7634c779 258 wait(3);
WD40andTape 9:cd3607ba5643 259
dofydoink 0:607bc887b6e0 260 timer.start();
WD40andTape 7:5b6a2cefbf3b 261
WD40andTape 10:1b6daba32452 262 threadLowLevelSPI.start(callback(&llcomms.queue, &EventQueue::dispatch_forever)); // Start the event queue
WD40andTape 7:5b6a2cefbf3b 263 threadReceiveAndReplan.start(ReceiveAndReplan);// Start replanning thread
WD40andTape 7:5b6a2cefbf3b 264 threadSmoothPathPlan.start(CalculateSmoothPath); // Start planning thread
WD40andTape 7:5b6a2cefbf3b 265
WD40andTape 7:5b6a2cefbf3b 266 PathCalculationTicker.attach(&startPathPlan, PATH_SAMPLE_TIME_S); // Set up planning thread to recur at fixed intervals
dofydoink 0:607bc887b6e0 267
WD40andTape 7:5b6a2cefbf3b 268 Thread::wait(1);
WD40andTape 1:2a43cf183a62 269 while(1) {
WD40andTape 1:2a43cf183a62 270 Thread::wait(osWaitForever);
dofydoink 0:607bc887b6e0 271 }
WD40andTape 7:5b6a2cefbf3b 272 }