//Test & Example to move robots static async Task TestMotionCommands(IUArm uArm) { Console.WriteLine("NOTE: Before testing the motion of the robot, "); Console.WriteLine(" - Move the robot arm to some position, such that the robot can move to any direction, by 50mm"); Console.WriteLine(" - Recommend to detach the heavy accessories like laser module, (for the case of test failure)"); Console.WriteLine(" - Check that the hand does not hit the robot itself with any rotation (no extremely large hand equipped)"); Console.WriteLine("Press ENTER to off the motor (be careful: the arm go down by the gravity!)"); Console.ReadLine(); await uArm.DetachAllMotorAsync(); await Task.Delay(500); Console.WriteLine("After moving the robot, press ENTER to on the motor (*robot does not move immediately, there is one more confirmation step)"); Console.ReadLine(); await uArm.AttachAllMotorAsync(); await Task.Delay(500); Console.WriteLine("Take a distance from robot, then press ENTER to start the motion test"); Console.ReadLine(); Console.WriteLine("Start motion test.."); //Get base state var currentPos = await uArm.GetPositionAsync(); var currentAngles = await uArm.GetAllServoAnglesAsync(); Console.WriteLine($"Current Pos : {currentPos}"); Console.WriteLine($"Current Angle: {currentAngles}"); #region Relative XYZ Console.WriteLine("Move by relative XYZ motion"); Console.WriteLine("+X"); await uArm.MoveRelativeAsync(new Position(50, 0, 0), 500); await Task.Delay(100); Console.WriteLine("-X"); await uArm.MoveRelativeAsync(new Position(-50, 0, 0), 500); await Task.Delay(100); Console.WriteLine("+Y"); await uArm.MoveRelativeAsync(new Position(0, 50, 0), 500); await Task.Delay(100); Console.WriteLine("-Y"); await uArm.MoveRelativeAsync(new Position(0, -50, 0), 500); await Task.Delay(100); Console.WriteLine("-Z"); await uArm.MoveRelativeAsync(new Position(0, 0, 50), 500); await Task.Delay(100); Console.WriteLine("-Z"); await uArm.MoveRelativeAsync(new Position(0, 0, -50), 500); await Task.Delay(100); Console.WriteLine($"Current Pos : {await uArm.GetPositionAsync()}"); Console.WriteLine($"Current Angle: {await uArm.GetAllServoAnglesAsync()}"); #endregion #region Relative Polar(SRH) Console.WriteLine("Move by relative Polar(SRH) motion"); Console.WriteLine("+S"); await uArm.MoveRelativeAsync(new Polar(50, 0, 0), 500); await Task.Delay(100); Console.WriteLine("-S"); await uArm.MoveRelativeAsync(new Polar(-50, 0, 0), 500); await Task.Delay(100); Console.WriteLine("+R"); await uArm.MoveRelativeAsync(new Polar(0, 10, 0), 500); await Task.Delay(100); Console.WriteLine("-R"); await uArm.MoveRelativeAsync(new Polar(0, -10, 0), 500); await Task.Delay(100); Console.WriteLine("-H"); await uArm.MoveRelativeAsync(new Polar(0, 0, 50), 500); await Task.Delay(100); Console.WriteLine("-H"); await uArm.MoveRelativeAsync(new Polar(0, 0, -50), 500); await Task.Delay(100); Console.WriteLine($"Current Pos : {await uArm.GetPositionAsync()}"); Console.WriteLine($"Current Angle: {await uArm.GetAllServoAnglesAsync()}"); #endregion #region Absolute Angle(Bottom, Left, Right, Hand) Console.WriteLine("Move by absolute angle(BLR, and Hand) input"); Console.WriteLine("Bottom +/-"); await uArm.MoveServoAngleAsync(Servos.Bottom, currentAngles.Bottom + 10.0f); await Task.Delay(500); await uArm.MoveServoAngleAsync(Servos.Bottom, currentAngles.Bottom); await Task.Delay(500); Console.WriteLine("Left +/-"); await uArm.MoveServoAngleAsync(Servos.Left, currentAngles.Left + 10.0f); await Task.Delay(500); await uArm.MoveServoAngleAsync(Servos.Left, currentAngles.Left); await Task.Delay(500); Console.WriteLine("Right +/-"); await uArm.MoveServoAngleAsync(Servos.Right, currentAngles.Right + 10.0f); await Task.Delay(500); await uArm.MoveServoAngleAsync(Servos.Right, currentAngles.Right); await Task.Delay(500); Console.WriteLine("Hand 0deg, 45deg, 135deg, 180deg, and 90deg"); await uArm.MoveServoAngleAsync(Servos.Hand, 0); await Task.Delay(500); await uArm.MoveServoAngleAsync(Servos.Hand, 45); await Task.Delay(500); await uArm.MoveServoAngleAsync(Servos.Hand, 135); await Task.Delay(500); await uArm.MoveServoAngleAsync(Servos.Hand, 180); await Task.Delay(500); await uArm.MoveServoAngleAsync(Servos.Hand, 90); await Task.Delay(500); #endregion #region Absolute XYZ / Polar Console.WriteLine("Move by absolute XYZ motion"); await uArm.MoveAsync(new Position(currentPos.X + 50, currentPos.Y + 50, currentPos.Z + 50), 500); await Task.Delay(100); await uArm.MoveAsync(currentPos, 500); await Task.Delay(100); Console.WriteLine("Move by absolute Polar motion"); var currentPolar = await uArm.GetPolarAsync(); await uArm.MoveAsync( new Polar(currentPolar.Stretch + 50, currentPolar.Rotation + 10, currentPolar.Height + 50), 500 ); await Task.Delay(100); await uArm.MoveAsync(currentPolar, 500); await Task.Delay(100); #endregion }
//Test & Example to call setter commands, except robot's motion // CAUTION: some operation includes output // - Beep (outputs some sound) // - Motor ON/OFF // - Suction cup ON/OFF // - Gripper ON/OFF // - Digital Out 0 ON/OFF static async Task TestNoMotionCommands(IUArm uArm) { await uArm.BeepAsync(440, 50); Console.WriteLine("Detach All Motors"); await uArm.DetachAllMotorAsync(); await Task.Delay(500); Console.WriteLine("Attach All Motors"); await uArm.AttachAllMotorAsync(); await Task.Delay(500); Console.WriteLine("Detach All Motors"); await uArm.DetachMotorAsync(Servos.Bottom); await uArm.DetachMotorAsync(Servos.Left); await uArm.DetachMotorAsync(Servos.Right); await Task.Delay(500); Console.WriteLine("Attach All Motors"); await uArm.AttachMotorAsync(Servos.Bottom); await uArm.AttachMotorAsync(Servos.Left); await uArm.AttachMotorAsync(Servos.Right); await Task.Delay(500); // Pos -> Angles by IK -> Pos by FK (Math) var pos = new Position(100, 100, 100); var angles = await uArm.GetIKAsync(pos); Console.WriteLine($"IK, src: X={pos.X}, Y={pos.Y}, Z={pos.Z}"); Console.WriteLine($"IK, res: L={angles.Bottom}, B={angles.Left}, R={angles.Right}"); pos = await uArm.GetFKAsync(angles); Console.WriteLine($"FK, src: L={angles.Bottom}, B={angles.Left}, R={angles.Right}"); Console.WriteLine($"FK, res: X={pos.X}, Y={pos.Y}, Z={pos.Z}"); // Can Reach or not pos = new Position(100, 100, 100); Console.WriteLine($"Can reach to (x,y,z)=({pos.X}, {pos.Y}, {pos.Z})? : {await uArm.CanReachAsync(pos)}"); pos = new Position(300, 300, 100); Console.WriteLine($"Can reach to (x,y,z)=({pos.X}, {pos.Y}, {pos.Z})? : {await uArm.CanReachAsync(pos)}"); var polar = new Polar(100, 45, 100); Console.WriteLine($"Can reach to (s,r,h)=({polar.Stretch}, {polar.Rotation}, {polar.Height})? : {await uArm.CanReachAsync(polar)}"); polar = new Polar(400, 200, 100); Console.WriteLine($"Can reach to (s,r,h)=({polar.Stretch}, {polar.Rotation}, {polar.Height})? : {await uArm.CanReachAsync(polar)}"); Console.WriteLine("Activate and deactivate the pump"); await Task.Delay(1000); await uArm.SetPumpStateAsync(true); await Task.Delay(1000); await uArm.SetPumpStateAsync(false); Console.WriteLine("Activate and deactivate the gripper"); await Task.Delay(1000); await uArm.SetGripperStateAsync(true); await Task.Delay(1000); await uArm.SetGripperStateAsync(false); // NO bluetooth operation, because when using this, serial connection will be shut down! //Console.WriteLine("Activate and deactivate the bluetooth"); //await Task.Delay(1000); //await uArm.SetBluetoothStateAsync(true); //await Task.Delay(1000); //await uArm.SetBluetoothStateAsync(false); Console.WriteLine("Change digital Out 0 to high, and low"); await Task.Delay(1000); await uArm.SetDigitalPinOutputAsync(0, true); await Task.Delay(1000); await uArm.SetDigitalPinOutputAsync(0, false); Console.WriteLine("Change ArmMode to Normal, Laser, Printing, Universal Holder, and then Normal again"); await Task.Delay(500); await uArm.SetArmModeAsync(ArmModes.Normal); await Task.Delay(500); await uArm.SetArmModeAsync(ArmModes.Laser); await Task.Delay(500); await uArm.SetArmModeAsync(ArmModes.Printing); await Task.Delay(500); await uArm.SetArmModeAsync(ArmModes.UniversalHolder); await Task.Delay(500); await uArm.SetArmModeAsync(ArmModes.Normal); Console.WriteLine("Set Current Position to the reference position"); try { await uArm.UpdateReferencePoint(); } catch (UArmException ex) { Console.WriteLine("Expected error, message: " + ex.Message); } Console.WriteLine("Set Height zero Point"); await uArm.UpdateHeightZeroPoint(); Console.WriteLine("Set End Effector Height 100mm, and 0mm"); await uArm.SetEndEffectorHeight(100); await uArm.SetEndEffectorHeight(0); }