private void UploadAction() { int actionId = GetSelectedActionId(); if (actionId < 0) { return; } char actionCode = UBT.actionTable.action[actionId].actionCode; if (MessageConfirm(String.Format("上傳動作 {0} 到機械人, 原有的資料將會被覆蓋", actionCode))) { StartSystemWork(); if (UBT.UploadAction(actionId)) { UpdateInfo(String.Format("機械人的動作{0} 成功更新了, 測試後請儲存到 SPIFFS", actionCode)); UBT.actionTable.action[actionId].actionFileExists = true; UBT.actionTable.action[actionId].poseLoaded = true; RefreshActionInfo(); } else { UpdateInfo(String.Format("更新機械人動作{0} 失敗", actionCode), UTIL.InfoType.error); } EndSystemWork(); } }
public void OnWindowClosing(object sender, CancelEventArgs e) { if (UBT.connected) { UBT.Disconnect(); } }
private void btnMp3Test_Click(object sender, RoutedEventArgs e) { UpdateInfo(); // byte folderSeq, fileSeq, playVol; if (!getMp3Folder(out byte folderSeq)) { return; } if (!getMp3File(out byte fileSeq, false)) { return; } if (!getMp3Vol(out byte playVol)) { return; } // For MP3 command using 9600bps software serial, it'd be better to add 100ms delay between each command UBT.V2_MP3Stop(); Thread.Sleep(100); if (playVol != 255) { UBT.V2_MP3SetVol(playVol); Thread.Sleep(100); } UBT.V2_MP3PlayFile(folderSeq, fileSeq); UpdateInfo(String.Format("播放 {0}档案 {1:0000}", (folderSeq == 0xFF ? "" : string.Format("{0:0000} 目录下的", folderSeq)), fileSeq)); }
private void PostConnection() { UBT.PostConnection(); ucActionList.Refresh(); ucMainServo.CheckServoType(); ucControlBoard.RefreshBoardConfig(); }
private void DeleteAction() { UpdateInfo(); int actionId = GetSelectedActionId(); if (actionId < 0) { return; } char actionCode = UBT.actionTable.action[actionId].actionCode; if (MessageConfirm(String.Format("刪除 SPIFFS 上動作 {0} 的檔案", actionCode))) { byte result = UBT.DeleteActionFile((byte)actionId); switch (result) { case 0: UpdateInfo("Action file deleted."); UBT.actionTable.action[actionId].actionFileExists = false; UBT.actionTable.action[actionId].Reset(); RefreshActionInfo(); break; case 12: UpdateInfo("Action file does not exists, delete is not required."); break; default: UpdateInfo("Fail deleting action file."); break; } } }
private void btnAutoFixAngle_Click(object sender, RoutedEventArgs e) { int angle = 0; try { angle = int.Parse(txtFixAngle.Text.Trim()); if ((angle < 0) || (angle > 180)) { UpdateInfo("輸入角度不正確", MyUtil.UTIL.InfoType.error); return; } } catch (Exception) { UpdateInfo("輸入角度不正確", MyUtil.UTIL.InfoType.error); return; } byte id = (byte)activeServo; if (UBT.V2_SetAngle(id, (byte)angle, 0)) { UBT.V2_MoveServo(id, (byte)angle, 50); } UBT.LockServo(id, true); UpdateActiveServo(); }
private void ServoLedChange(object sender, EventArgs e) { uc.UcServo ucServo = (uc.UcServo)sender; byte id = ucServo.id; if ((id < 1) || (id > CONST.MAX_SERVO)) { return; } byte mode = servo[id].led; switch (mode) { case CONST.LED.NO_CHANGE: mode = CONST.LED.TURN_ON; UBT.V2_SetLED(id, 0); break; case CONST.LED.TURN_ON: mode = CONST.LED.TURN_OFF; UBT.V2_SetLED(id, 1); break; default: mode = CONST.LED.NO_CHANGE; break; } servo[id].SetLED(mode); servo[id].Show(); if (activeServo == id) { UpdateActiveServoInfo(); } }
private void DownloadAction() { int actionId = GetSelectedActionId(); if (actionId < 0) { return; } char actionCode = UBT.actionTable.action[actionId].actionCode; if (MessageConfirm(String.Format("下載動作 {0} 的資料, 當前資料將會被覆蓋", actionCode))) { StartSystemWork(); if (UBT.DownloadAction((byte)actionId, true)) { UpdateInfo(String.Format("動作{0} 成功下載", actionCode)); } else { UpdateInfo(String.Format("下載動作{0} 失敗", actionCode), UTIL.InfoType.error); } RefreshActionInfo(); EndSystemWork(); } }
private void SetServoAdjAngle() { UpdateInfo(); if (activeServo > 0) { byte id = (byte)activeServo; int n = (int)sliderAdjValue.Value; if (n < 0) { n += 65536; } UInt16 adjValue = (UInt16)n; if (!UBT.V2_SetAdjAngle(id, adjValue)) { UpdateInfo("Fail setting servo adjustment", UTIL.InfoType.error); return; } if ((txtAdjPreview.Text == null) || (txtAdjPreview.Text.Trim() == "")) { return; } byte angle = (byte)Convert.ToInt32(txtAdjPreview.Text, 10); UBT.V2_MoveServo(id, angle, 50); } }
private void btnAutoFixAngle_Click(object sender, RoutedEventArgs e) { if (activeServo > 0) { byte id = (byte)activeServo; string sFixAngle = txtFixAngle.Text.Trim(); if (sFixAngle == "") { UpdateInfo("Please enter current angle", UTIL.InfoType.error); return; } int iFixAngle; if ((!int.TryParse(sFixAngle, out iFixAngle)) || (iFixAngle < 0) || (iFixAngle > 180)) { UpdateInfo("Invalid angle, should be 0 ~ 180", UTIL.InfoType.error); return; } // first get current adjustment UInt16 adj = UBT.V2_GetAdjAngle(id); if (adj == 0x7F7F) { return; } int adjValue = 0; if ((adj >= 0x0000) && (adj <= 0x0130)) { adjValue = adj; } else if ((adj >= 0xFED0) && (adj <= 0xFFFF)) { adjValue = (adj - 65536); } else { UpdateInfo("Invalid adjustment", UTIL.InfoType.error); return; } // get current angle Byte currAngle = UBT.V2_GetAngle(id); if (currAngle == 0xFF) { return; } int delta = cboDelta.SelectedIndex; // adjValue = 3 * angle int newAdjValue = (currAngle - iFixAngle) * 3 + adjValue; if (newAdjValue < 0) { newAdjValue += 65536 + delta; } SetAdjAngle(newAdjValue); txtAdjPreview.Text = sFixAngle; SetServoAdjAngle(); } }
private void btnResetServo_Click(object sender, RoutedEventArgs e) { if (activeServo <= 0) { return; } UBT.V2_ServoCommand((byte)activeServo, 1); }
private void PostDisconnect() { UBT.PostDisconnect(); ucActionList.Refresh(); ucActionDetail.Refresh(); ucControlBoard.RefreshBoardConfig(); ClearBattery(); ClearMpu(); }
public void UpdateBattery() { // Just for safety, in case front-end submit request at the same time UInt16 value; byte power; UBT.CheckBattery(out value, out power); UIUpdateBattery(value, power); }
private void ReadAdjAngle() { UpdateInfo(); UInt16 adj = UBT.V2_GetAdjAngle((byte)activeServo); if (adj != 0x7F7F) { SetAdjAngle((int)adj); } }
private void cbxActiveLocked_Changed(object sender, RoutedEventArgs e) { if ((!updating_servo_info) && (activeServo > 0)) { bool goLock = (this.cbxActiveLocked.IsChecked == true); List <data.ServoInfo> lsi = new List <data.ServoInfo>(); lsi.Add(new data.ServoInfo((byte)activeServo)); UBT.LockServo(lsi, goLock); UpdateActiveServoInfo(); } }
private void rbHeadLed_Clicked(object sender, RoutedEventArgs e) { if (rbHeadLedTurnOff.IsChecked == true) { UBT.V2_SetHeadLED(0); } else if (rbHeadLedTurnOn.IsChecked == true) { UBT.V2_SetHeadLED(1); } }
private void ActionList_StopAction(object sender, EventArgs e) { UpdateInfo(); if (UBT.StopAction()) { UpdateInfo("动作播放停止了"); } else { UpdateInfo("停止播放动作出错"); } }
private void SetDebug(bool mode) { UpdateInfo(); if (UBT.SetDebug(mode)) { UpdateInfo(String.Format("除虫模式已{0}", (mode ? "启动" : "停止"))); } else { UpdateInfo("设定除虫模式失败"); } }
public void ReadAdjAngle() { UpdateInfo(); if (activeServo <= 0) { return; } UInt16 adj = UBT.V2_GetAdjAngle((byte)activeServo); if (adj != 0x7F7F) { SetAdjAngle((int)adj); } }
private void SetSelectedServoLock(bool goLock) { List <data.ServoInfo> lsi = new List <data.ServoInfo>(); for (byte i = 1; i <= CONST.MAX_SERVO; i++) { if (servo[i].isSelected) { lsi.Add(new data.ServoInfo(i)); } } UBT.LockServo(lsi, goLock); UpdateActiveServoInfo(); }
private void sliderTimer_Tick(object sender, EventArgs e) { if (activeServo > 0) { sliderTimer.Stop(); double dblAngle = Math.Round(sliderActiveAngle.Value); byte angle = (byte)dblAngle; byte oldAngle = servo[activeServo].angle; // if (angle == oldAngle) return; double diff = (byte)Math.Abs(angle - oldAngle); byte time = (byte)(Math.Round(40.0 * diff / CONST.SERVO.MAX_ANGLE)); // 40 ~ 1s, 1s for 240 angle UBT.MoveServo((byte)activeServo, angle, time); int TimeMs = time * 25 + 100; // add extra 100ms, seeem still not work, sometimes command cannot be executed for fast change. servoEndTicks = DateTime.Now.Ticks + TimeMs * TimeSpan.TicksPerMillisecond; } }
private void btnReadPose_Click(object sender, RoutedEventArgs e) { UpdateInfo(); data.PoseInfo pi = ucActionDetail.GetSelectedPose(); if (pi == null) { UpdateInfo("没有选定姿势", MyUtil.UTIL.InfoType.alert); } else { UBT.SetPose(pi.actionId, pi.poseId); for (int i = 1; i <= CONST.MAX_SERVO; i++) { servo[i].SetLED(pi.servoLed[i]); servo[i].Show(); } if (activeServo > 0) { rbLedNoChange.IsChecked = (pi.servoLed[activeServo] == CONST.LED.NO_CHANGE); rbLedTurnOn.IsChecked = (pi.servoLed[activeServo] == CONST.LED.TURN_ON); rbLedTurnOff.IsChecked = (pi.servoLed[activeServo] == CONST.LED.TURN_OFF); } rbHeadLedNoChange.IsChecked = (pi.headLed == CONST.LED.NO_CHANGE); rbHeadLedTurnOn.IsChecked = (pi.headLed == CONST.LED.TURN_ON); rbHeadLedTurnOff.IsChecked = (pi.headLed == CONST.LED.TURN_OFF); if (pi.mp3Vol == CONST.AI.STOP_MUSIC_VOL) { cbxStopMp3.IsChecked = true; tbMp3Folder.Text = ""; tbMp3File.Text = ""; tbMp3Vol.Text = ""; } else { cbxStopMp3.IsChecked = false; tbMp3Folder.Text = (pi.mp3Folder == 0xff ? "" : pi.mp3Folder.ToString()); tbMp3File.Text = (pi.mp3File == 0xff ? "" : pi.mp3File.ToString()); tbMp3Vol.Text = (pi.mp3Vol == 0xff ? "" : pi.mp3Vol.ToString()); } tbExecTime.Text = pi.servoTime.ToString(); tbWaitTime.Text = pi.waitTime.ToString(); } }
public void UpdateMpu() { if (!UBT.mpuExists) { return; } Int16 ax, ay, az; if (UBT.GetMpuData(out ax, out ay, out az)) { UIUdateMpu(ax.ToString(), ay.ToString(), az.ToString()); } else { UIUdateMpu(); } }
private void DownloadActionTable() { if (MessageConfirm("從機械人重新下載所有動作, 當前資料將會被覆蓋")) { StartSystemWork(); if (UBT.DownloadActionTable()) { UpdateInfo("下載資料完成"); } else { UpdateInfo("下載資料失敗"); } RefreshActionInfo(); EndSystemWork(); } }
private void UpdateAngle() { if (activeServo > 0) { string sAngle = tbAngle.Text.Trim(); int angle; if (!int.TryParse(sAngle, out angle)) { return; } if ((angle < 0) || (angle > 240)) { UpdateInfo(string.Format("Invalid angle: {0}", angle)); } sliderActiveAngle.Value = angle; UBT.MoveServo((byte)activeServo, (byte)angle, 0); } }
private void sliderTimer_Tick(object sender, EventArgs e) { sliderTimer.Stop(); double dblAngle = Math.Round(sliderActiveAngle.Value); byte angle = (byte)dblAngle; UBT.MoveServo((byte)activeServo, angle, 0); if (sliderMode > 0) { // extra one time after stop if (sliderMode == 1) { sliderMode = 0; } sliderTimer.Start(); } }
private void rbLed_Clicked(object sender, RoutedEventArgs e) { if (activeServo > 0) { byte mode = CONST.LED.NO_CHANGE; if (rbLedTurnOff.IsChecked == true) { mode = CONST.LED.TURN_OFF; UBT.V2_SetLED((byte)activeServo, 1); } else if (rbLedTurnOn.IsChecked == true) { mode = CONST.LED.TURN_ON; UBT.V2_SetLED((byte)activeServo, 0); } servo[activeServo].SetLED(mode); servo[activeServo].Show(); } }
private void SetAllLed(byte mode) { UpdateInfo(); for (int i = 1; i <= CONST.MAX_SERVO; i++) { servo[i].SetLED(mode); servo[i].Show(); } if (mode == CONST.LED.TURN_ON) { UBT.V2_SetLED(0, 0); } else if (mode == CONST.LED.TURN_OFF) { UBT.V2_SetLED(0, 1); } if (activeServo > 0) { UpdateActiveServoInfo(); } }
private void InitServo() { ConfigObject CONFIG = SYSTEM.configObject; gridRobot.Background = loadImage(CONFIG); for (byte i = 1; i <= CONFIG.max_servo; i++) { uc.UcServo us = new uc.UcServo(UBT.GetServo(i)); us.Width = 38; us.Height = 38; us.HorizontalAlignment = HorizontalAlignment.Left; us.VerticalAlignment = VerticalAlignment.Top; // us.Margin = new Thickness(servoPos[i, 0], servoPos[i, 1], 0, 0); us.Margin = new Thickness(CONFIG.servos[i - 1].X, CONFIG.servos[i - 1].Y, 0, 0); us.Show(); us.MouseDownEventHandler += Servo_MouseDown; servo[i] = us; gridRobot.Children.Add(us); } }
private void ServoLockChange(object sender, EventArgs e) { uc.UcServo ucServo = (uc.UcServo)sender; byte id = ucServo.id; if ((id < 1) || (id > CONST.MAX_SERVO)) { return; } bool goLock = !servo[id].locked; List <data.ServoInfo> lsi = new List <data.ServoInfo>(); lsi.Add(new data.ServoInfo(id)); UBT.LockServo(lsi, goLock); // servo[id].Show(); if (activeServo == id) { UpdateActiveServoInfo(); } }