public void RunServoMotion(ServoMotor Motor, List <ServoPosition> MotionProfile, int NumIterations) { //Clear any exisiting motion profile for the selected motor CancelServoMotion(Motor); //add to the execution list MotionExecutionState state = new MotionExecutionState(); state.Motor = Motor; state.LastUpdateTime = m_stopWatch.ElapsedMilliseconds; state.MotionProfile = MotionProfile; state.TotalIterations = NumIterations; state.isRunning = (MotionProfile.Count > 0); if (state.isRunning) { state.CurrentAngle = MotionProfile[0].TargetAngle; } else { state.CurrentAngle = Motor.MaxAngle / 2; } m_ExecutionList.Add(state); //ensure update timer is enabled m_updateTimer.Enabled = true; }
public bool IsMotorRunning(ServoMotor Motor) { uint motorID = Motor.PWMHardwareIndex; for (int i = 0; i < m_ExecutionList.Count; i++) { if (m_ExecutionList[i].Motor.PWMHardwareIndex == motorID) { return(m_ExecutionList[i].isRunning); } } return(false); }
public void CancelServoMotion(ServoMotor Motor) { bool motorFound = false; for (int i = 0; i < m_ExecutionList.Count; i++) { if (Motor == m_ExecutionList[i].Motor) { m_ExecutionList.RemoveAt(i); motorFound = true; break; } } if (!motorFound) { throw new ArgumentException("ERROR: Could not find motor to cancel motion"); } }
public void PauseServoMotion(ServoMotor Motor) { bool motorFound = false; for (int i = 0; i < m_ExecutionList.Count; i++) { if (Motor == m_ExecutionList[i].Motor) { m_ExecutionList[i].isRunning = false; motorFound = true; break; } } if (!motorFound) { throw new ArgumentException("ERROR: Paused motor not found"); } }
public void ResumeServoMotion(ServoMotor Motor) { bool motorFound = false; for (int i = 0; i < m_ExecutionList.Count; i++) { if (Motor == m_ExecutionList[i].Motor) { m_ExecutionList[i].isRunning = true; motorFound = true; m_updateTimer.Enabled = true; break; } } if (!motorFound) { throw new ArgumentException("ERROR: Could not find motor to resume"); } }
/// <summary> /// Run motion profile forever until cancelled. Repeats from the start of the profile. /// </summary> /// <param name="Motor">The motor to run the motion profile on</param> /// <param name="MotionProfile">The profile to run</param> public void RunServoMotion(ServoMotor Motor, List <ServoPosition> MotionProfile) { //call overload with multiple iterations. -1 means infinite RunServoMotion(Motor, MotionProfile, -1); }