Revision af93a91c devices/DiWheelDrive/linefollow2.cpp
devices/DiWheelDrive/linefollow2.cpp | ||
---|---|---|
11 | 11 |
this->global = global; |
12 | 12 |
} |
13 | 13 |
|
14 |
// void LineFollow::followLine(int vcnl4020Proximity[4], int (&rpmFuzzyCtrl)[2], Global *global){ |
|
15 |
|
|
16 |
// chprintf((BaseSequentialStream*) &SD1, "SP: %d,\n", SetPoint); |
|
17 |
|
|
18 |
// // chprintf((BaseSequentialStream*) &SD1, "Proximity: WL:0x%04X FL:0x%04X FR:0x%04X WR:0x%04X\n", |
|
19 |
// // vcnl4020Proximity[constants::DiWheelDrive::PROX_WHEEL_LEFT], |
|
20 |
// // vcnl4020Proximity[constants::DiWheelDrive::PROX_FRONT_LEFT], |
|
21 |
// // vcnl4020Proximity[constants::DiWheelDrive::PROX_FRONT_RIGHT], |
|
22 |
// // vcnl4020Proximity[constants::DiWheelDrive::PROX_WHEEL_RIGHT]); |
|
23 |
// // global->motorcontrol.printGains(); |
|
24 |
// // chprintf((BaseSequentialStream*) &SD1, "Speed -- Left: %d, Right: %d\n", global->motorcontrol.getCurrentRPMLeft(), global->motorcontrol.getCurrentRPMRight()); |
|
25 |
|
|
26 |
|
|
27 |
// // float speedL = global->motorcontrol.getCurrentRPMLeft(); |
|
28 |
// // float speedR = global->motorcontrol.getCurrentRPMRight(); |
|
29 |
// // chprintf((BaseSequentialStream*) &SD1, "After motor request SP: %f,\n", SetPoint); |
|
30 |
// // Process value |
|
31 |
// float processV = static_cast< float >((vcnl4020Proximity[constants::DiWheelDrive::PROX_FRONT_LEFT] + vcnl4020Proximity[constants::DiWheelDrive::PROX_FRONT_RIGHT])); |
|
32 |
// // chprintf((BaseSequentialStream*) &SD1, "PV: %f,\n", processV); |
|
33 |
// // chprintf((BaseSequentialStream*) &SD1, "After PV SP: %f,\n", SetPoint); |
|
34 |
// float error = SetPoint - processV; |
|
35 |
// float d_term = old_error - error; |
|
36 |
// // chprintf((BaseSequentialStream*) &SD1, "After Error SP: %f,\n", SetPoint); |
|
37 |
// // chprintf((BaseSequentialStream*) &SD1, "Error: %f,\n", error); |
|
38 |
// acc_sum = 0.5 * acc_sum + error; |
|
39 |
// int correctionSpeed = static_cast< int >(Kp * error + Ki*acc_sum + Kd*d_term); |
|
40 |
// old_error = error; |
|
41 |
// chprintf((BaseSequentialStream*) &SD1, "Error: %f,\n", error); |
|
42 |
// chprintf((BaseSequentialStream*) &SD1, "Dterm: %f,\n", d_term); |
|
43 |
// chprintf((BaseSequentialStream*) &SD1, "Iterm: %f,\n", acc_sum); |
|
44 |
// chprintf((BaseSequentialStream*) &SD1, "New Speed: %d,\n", correctionSpeed); |
|
45 |
// // chprintf((BaseSequentialStream*) &SD1, "New Speed: %f, Sum: %f, SP: %f, processV: %f, K_p: %f, K_i: %f \n", correctionSpeed, acc_sum, SetPoint, processV, Kp, Ki); |
|
46 |
|
|
47 |
// // int forward = 15; |
|
48 |
// int speedL = global->rpmForward[constants::DiWheelDrive::LEFT_WHEEL] - correctionSpeed; |
|
49 |
// int speedR = global->rpmForward[constants::DiWheelDrive::RIGHT_WHEEL] + correctionSpeed; |
|
50 |
|
|
51 |
// // if (l_speed ) |
|
52 |
|
|
53 |
// rpmFuzzyCtrl[constants::DiWheelDrive::LEFT_WHEEL] = speedL; |
|
54 |
// rpmFuzzyCtrl[constants::DiWheelDrive::RIGHT_WHEEL] = speedR; |
|
55 |
|
|
56 |
// chprintf((BaseSequentialStream*) &SD1, "Speed L: %d, R: %d\n", speedL, speedR); |
|
57 |
|
|
58 |
// } |
|
14 |
int LineFollow::delta(){ |
|
15 |
int delta = 0; |
|
16 |
int FL = global->vcnl4020[constants::DiWheelDrive::PROX_FRONT_LEFT].getProximityScaledWoOffset(); |
|
17 |
int FR = global->vcnl4020[constants::DiWheelDrive::PROX_FRONT_RIGHT].getProximityScaledWoOffset(); |
|
18 |
|
|
19 |
delta = abs(abs(global->threshProxyL-global->threshProxyR) - abs(FL-FR)); |
|
20 |
|
|
21 |
if (FR > global->threshProxyR && FL > global->threshProxyL ){ |
|
22 |
return delta * -1; |
|
23 |
}else { |
|
24 |
return delta; |
|
25 |
} |
|
26 |
return delta; |
|
27 |
} |
|
59 | 28 |
|
60 | 29 |
|
61 | 30 |
void LineFollow::stableFollow(int vcnl4020Proximity[4], int (&rpmFuzzyCtrl)[2], Global *global){ |
... | ... | |
84 | 53 |
|
85 | 54 |
} |
86 | 55 |
|
87 |
int calculateError(){ |
|
88 |
|
|
89 |
} |
|
90 | 56 |
|
91 |
void calibrateZiegler(int (&rpmFuzzyCtrl)[2], Global *global){ |
|
92 | 57 |
|
93 |
} |
|
58 |
void LineFollow::calibrateZiegler(float KCrit, int rpmSpeed[2]){ |
|
59 |
int targetSpeedL = 5; |
|
60 |
int targetSpeedR = 5; |
|
94 | 61 |
|
95 |
// void LineFollow::followLineSeperateSensors2(int vcnl4020Proximity[4], int (&rpmFuzzyCtrl)[2], Global *global){ |
|
96 |
|
|
97 |
// chprintf((BaseSequentialStream*) &SD1, "SP: %d,\n", SetPoint); |
|
98 |
// int targetSensorL = 0x10; |
|
99 |
// int targetSensorR = 0x28; |
|
100 |
|
|
101 |
// float actualSpeedL = 20; |
|
102 |
// float actualSpeedR = 20; |
|
103 |
|
|
104 |
// // if(actualSpeedL == 0){ |
|
105 |
// // actualSpeedL = 1; |
|
106 |
// // } |
|
107 |
// // if(actualSpeedR == 0){ |
|
108 |
// // actualSpeedR = 1; |
|
109 |
// // } |
|
110 |
|
|
111 |
// // Shift sensor values to prevent overflow in following calculation |
|
112 |
// int actualSensorL = vcnl4020Proximity[constants::DiWheelDrive::PROX_FRONT_LEFT] >> 8; |
|
113 |
// int actualSensorR = vcnl4020Proximity[constants::DiWheelDrive::PROX_FRONT_RIGHT] >> 8; |
|
114 |
// chprintf((BaseSequentialStream*) &SD1, "Sensor L: %d, R: %d\n", actualSensorL, actualSensorR); |
|
115 |
|
|
116 |
// int targetSpeedL = global->rpmForward[constants::DiWheelDrive::LEFT_WHEEL]; |
|
117 |
// int targetSpeedR = global->rpmForward[constants::DiWheelDrive::RIGHT_WHEEL]; |
|
118 |
|
|
119 |
// int setPointL = targetSensorL; |
|
120 |
// int setPointR = targetSensorR; |
|
121 |
// chprintf((BaseSequentialStream*) &SD1, "SetPoint L: %d, R: %d\n",setPointL, setPointR ); |
|
122 |
|
|
123 |
// int processValueL = actualSensorL; |
|
124 |
// int processValueR = actualSensorR; |
|
125 |
// chprintf((BaseSequentialStream*) &SD1, "ProcessValue L: %d, R: %d\n",processValueL, processValueR ); |
|
126 |
|
|
127 |
// int errorL = setPointL - processValueL; |
|
128 |
// int errorR = setPointR - processValueR; |
|
129 |
|
|
130 |
// // This will howfully decrease the overall speed when sensors deviate much |
|
131 |
// // errorL /= targetSensorL+actualSensorL; |
|
132 |
// // errorR /= targetSensorR+actualSensorR; |
|
133 |
// chprintf((BaseSequentialStream*) &SD1, "Error L: %d, R: %d\n",errorL, errorR); |
|
134 |
|
|
135 |
// // int newSpeedL = |
|
136 |
// rpmFuzzyCtrl[constants::DiWheelDrive::LEFT_WHEEL] = errorL; |
|
137 |
// rpmFuzzyCtrl[constants::DiWheelDrive::RIGHT_WHEEL] = errorR; |
|
62 |
int correctionSpeed = (int) (KCrit * delta()); |
|
138 | 63 |
|
139 |
// int correction_speedL = (int) (Kp * errorL); |
|
140 |
// int correction_speedR = (int) (Kp * errorR); |
|
141 |
// chprintf((BaseSequentialStream*) &SD1, "Speed L: %d, R: %d\n",correction_speedL, correction_speedR); |
|
142 |
|
|
143 |
// // // chprintf((BaseSequentialStream*) &SD1, "After motor request SP: %f,\n", SetPoint); |
|
144 |
// // // Process value |
|
145 |
// // float processV = static_cast< float >((vcnl4020Proximity[constants::DiWheelDrive::PROX_FRONT_LEFT] + vcnl4020Proximity[constants::DiWheelDrive::PROX_FRONT_RIGHT])); |
|
146 |
// // // chprintf((BaseSequentialStream*) &SD1, "PV: %f,\n", processV); |
|
147 |
// // // chprintf((BaseSequentialStream*) &SD1, "After PV SP: %f,\n", SetPoint); |
|
148 |
// // float error = SetPoint - processV; |
|
149 |
// // float d_term = old_error - error; |
|
150 |
// // // chprintf((BaseSequentialStream*) &SD1, "After Error SP: %f,\n", SetPoint); |
|
151 |
// // // chprintf((BaseSequentialStream*) &SD1, "Error: %f,\n", error); |
|
152 |
// // acc_sum = 0.5 * acc_sum + error; |
|
153 |
// // int new_speed = static_cast< int >(Kp * error + Ki*acc_sum + Kd*d_term); |
|
154 |
// // old_error = error; |
|
155 |
// // chprintf((BaseSequentialStream*) &SD1, "Error: %f,\n", error); |
|
156 |
// // chprintf((BaseSequentialStream*) &SD1, "Dterm: %f,\n", d_term); |
|
157 |
// // chprintf((BaseSequentialStream*) &SD1, "Iterm: %f,\n", acc_sum); |
|
158 |
// // chprintf((BaseSequentialStream*) &SD1, "New Speed: %d,\n", new_speed); |
|
159 |
// // // chprintf((BaseSequentialStream*) &SD1, "New Speed: %f, Sum: %f, SP: %f, processV: %f, K_p: %f, K_i: %f \n", new_speed, acc_sum, SetPoint, processV, Kp, Ki); |
|
160 |
|
|
161 |
// // // int forward = 15; |
|
162 |
// // // int l_speed = forward - new_speed; |
|
163 |
// // // int r_speed = forward + new_speed; |
|
164 |
|
|
165 |
// // // if (l_speed ) |
|
166 |
|
|
167 |
// rpmFuzzyCtrl[constants::DiWheelDrive::LEFT_WHEEL] = targetSpeedL + correction_speedL; |
|
168 |
// rpmFuzzyCtrl[constants::DiWheelDrive::RIGHT_WHEEL] = targetSpeedR + correction_speedR; |
|
169 |
|
|
170 |
// // chprintf((BaseSequentialStream*) &SD1, "Speed L: %d, R: %d\n", rpmFuzzyCtrl[constants::DiWheelDrive::LEFT_WHEEL], rpmFuzzyCtrl[constants::DiWheelDrive::RIGHT_WHEEL]); |
|
171 |
|
|
172 |
// } |
|
64 |
rpmSpeed[constants::DiWheelDrive::LEFT_WHEEL] = targetSpeedL + correctionSpeed; |
|
65 |
rpmSpeed[constants::DiWheelDrive::RIGHT_WHEEL] = targetSpeedR - correctionSpeed; |
|
66 |
chprintf((BaseSequentialStream*) &SD1, "CS:%d,LW:%d,RW:%d\n", correctionSpeed, rpmSpeed[constants::DiWheelDrive::LEFT_WHEEL], rpmSpeed[constants::DiWheelDrive::RIGHT_WHEEL]); |
|
67 |
} |
Also available in: Unified diff