序號 | 名稱 | 數量 |
---|---|---|
1 | Arduino UNO | 1 |
2 | simpleFOCShield V2.0.3 | 1 |
3 | 雲台馬達 | 1 |
4 | 12V電源 | 1 |
5 | 方口USB線 | 1 |
void setPhaseVoltage(float Uq, float Ud, float angle_el) { int sector = (angle_el / _PI_3) + 1; // find the sector we are in currently float T1 = _SQRT3*_sin(sector*_PI_3 - angle_el) * Uq/driver.voltage_limit; float T2 = _SQRT3*_sin(angle_el - (sector-1)*_PI_3) * Uq/driver.voltage_limit; float T0 = 1 - T1 - T2; float Ta,Tb,Tc; switch(sector){ case 1: Ta = T1 + T2 + T0/2; Tb = T2 + T0/2; Tc = T0/2; break; case 2: Ta = T1 + T0/2; Tb = T1 + T2 + T0/2; Tc = T0/2; break; case 3: Ta = T0/2; Tb = T1 + T2 + T0/2; Tc = T2 + T0/2; break; case 4: Ta = T0/2; Tb = T1+ T0/2; Tc = T1 + T2 + T0/2; break; case 5: Ta = T2 + T0/2; Tb = T0/2; Tc = T1 + T2 + T0/2; break; case 6: Ta = T1 + T2 + T0/2; Tb = T0/2; Tc = T1 + T0/2; break; default: // possible error state Ta = 0; Tb = 0; Tc = 0; } // calculate the phase voltages and center float Ua = Ta*driver.voltage_limit; float Ub = Tb*driver.voltage_limit; float Uc = Tc*driver.voltage_limit; driver.setPwm(Ua,Ub,Uc); }
void serialReceiveUserCommand() { // a string to hold incoming data static String received_chars; while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); // add it to the string buffer: received_chars += inChar; // end of user input if (inChar == '\n') { // change the motor target theta = received_chars.toFloat(); Serial.print("Target Angle:"); Serial.println(theta); // reset the command buffer received_chars = ""; } } }