/// <summary> /// Pohnutí s motorem na danou pozici vzhledem k homingu /// </summary> /// <param name="position">absolutní pozice</param> public void moveToPosition(int position) { if (limitEnable && hasPositionLimit && position <= minPosition) { position = minPosition; SystemSounds.Beep.Play(); } if (limitEnable && hasPositionLimit && position >= maxPosition) { position = maxPosition; SystemSounds.Beep.Play(); } try { targetPosition = position; targetAngle = getAngleFromPosition(targetPosition); positionHandler.MoveToPosition(Convert.ToInt32(position), true, true); } catch (DeviceException e) { state = MotorState.error; stateObserver.motorStateChanged(MotorState.error, String.Format("{0}\nError: {1}", e.ErrorMessage, errorDictionary.getComunicationErrorMessage(e.ErrorCode)), id, 0, 0, 0, 0); motorErrorOccuredObserver(); } }
/// <summary> /// Handles the Click event of the buttonMove control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="ea">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void ButtonMoveClick(object sender, EventArgs ea) { try { ProfilePositionMode ppm = _epos.Operation.ProfilePositionMode; ppm.ActivateProfilePositionMode(); textBoxAOM.Text = _epos.Operation.OperationMode.GetOperationModeAsString(); textBoxPositionStart.Text = string.Format("{0}", _epos.Operation.MotionInfo.GetPositionIs()); ppm.MoveToPosition(Convert.ToInt32(textBoxTargetPosition.Text), radioButtonAbsoluteMove.Checked, true); } catch (DeviceException e) { StopRefresh(); ShowMessageBox(e.ErrorMessage, e.ErrorCode); } catch (Exception e) { StopRefresh(); MessageBox.Show(e.Message); } }
/// <summary> /// makes both wheels turn until the given distance is reached /// </summary> /// <param name="distance">distance in cm, already multiplied by -2000</param> /// <returns>bool that indicates, if operation was successful</returns> public bool MoveToPosition(int distance) { try { //PositionMode is needed to let robot drive a given distance ActivatePositionMode(); //both wheels should turn _ppm1.MoveToPosition(distance, false, true); _ppm2.MoveToPosition(distance, false, true); //returns true, if MoveToPosition() was successful return(true); } //an error may occur catch (Exception e) { ConsoleFormatter.Error("Failed to move for " + distance + "cm", "Message: " + e.Message); //returns false if MoveToPosition() fails return(false); } }
private void joy_update(object sender, EventArgs e) { if (ctrl != null && ctrl.IsConnected == true) { state = ctrl.GetState(); gamepad = ctrl.GetState().Gamepad; var joy = new xbox_joy(); var buttons = ""; #region get joy data gamepad = ctrl.GetState().Gamepad; buttons = gamepad.Buttons.ToString(); joy.A = buttons.Contains("A"); joy.B = buttons.Contains("B"); joy.X = buttons.Contains("X"); joy.Y = buttons.Contains("Y"); joy.start = buttons.Contains("Start"); joy.back = buttons.Contains("Back"); joy.left_shoulder = buttons.Contains("LeftShoulder"); joy.right_shoulder = buttons.Contains("RightShoulder"); joy.rightthumb = buttons.Contains("RightThumb"); joy.leftthumb = buttons.Contains("LeftThumb"); joy.dpadUp = buttons.Contains("DPadUp"); joy.dpadLeft = buttons.Contains("DPadLeft"); joy.dpadDown = buttons.Contains("DPadDown"); joy.dpadRight = buttons.Contains("DPadRight"); joy.left_axis_x = gamepad.LeftThumbX + 32768; joy.left_axis_y = gamepad.LeftThumbY + 32768; joy.right_axis_x = gamepad.RightThumbX + 32768; joy.right_axis_y = gamepad.RightThumbY + 32768; joy.left_trigger = gamepad.LeftTrigger; joy.right_trigger = gamepad.RightTrigger; #endregion this.label_left_trigger.Text = joy.left_trigger.ToString(); this.label_right_trigger.Text = joy.right_trigger.ToString(); this.label_left_axis_x.Text = joy.left_axis_x.ToString(); this.label_left_axis_y.Text = joy.left_axis_y.ToString(); this.label_right_axis_x.Text = joy.right_axis_x.ToString(); this.label_right_axis_y.Text = joy.right_axis_y.ToString(); if (joy.start) { this.checkBox_use_joy.Checked = true; } if (joy.back) { this.checkBox_use_joy.Checked = false; } this.checkBox_use_joy.Visible = true; // MOVE !!!! if (checkBox_use_joy.Checked == true) { try { ProfilePositionMode ppm = _epos_A.Operation.ProfilePositionMode; ppm.ActivateProfilePositionMode(); textBoxAOM_A.Text = _epos_A.Operation.OperationMode.GetOperationModeAsString(); ppm.MoveToPosition(joy.left_axis_x, true, true); } catch { } try { ProfilePositionMode ppm = _epos_B.Operation.ProfilePositionMode; ppm.ActivateProfilePositionMode(); textBoxAOM_B.Text = _epos_B.Operation.OperationMode.GetOperationModeAsString(); ppm.MoveToPosition(joy.right_axis_x, true, true); } catch { } } } else { this.checkBox_use_joy.Visible = false; } }