Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using NUnit.Framework;
  4.  
  5.  
  6. namespace Manipulation
  7. {
  8. public static class ManipulatorTask
  9. {
  10. public static double[] MoveManipulatorTo(double x, double y, double angle)
  11. {
  12. var firstCatheterPalm = Manipulator.Palm * Math.Cos(angle);
  13. var firstX = x - firstCatheterPalm;
  14. var firstY = y;
  15. var secondCatheterPalm = Manipulator.Palm * Math.Sin(angle);
  16. var secondX = firstX;
  17. double secondY = firstY + secondCatheterPalm;
  18. var sideShoulderWrist = Math.Sqrt(Math.Pow(secondX, 2) + Math.Pow(secondY, 2));
  19. var elbow = TriangleTask.GetABAngle(Manipulator.UpperArm, Manipulator.Forearm, sideShoulderWrist);
  20. var oxShoulderWristCorner = Math.Atan2(secondY, secondX);
  21. var shoulder = TriangleTask.GetABAngle(sideShoulderWrist, Manipulator.UpperArm, Manipulator.Forearm) + oxShoulderWristCorner;
  22. var wrist = -angle - shoulder - elbow;
  23. if (double.IsNaN(elbow) || double.IsNaN(shoulder) || double.IsNaN(wrist))
  24. {
  25. wrist = double.NaN;
  26. elbow = double.NaN;
  27. shoulder = double.NaN;
  28. }
  29. return new[] { shoulder, elbow, wrist };
  30. }
  31. }
  32. [TestFixture]
  33. public class ManipulatorTask_Tests
  34. {
  35. [Test]
  36. public void TestMoveManipulatorTo()
  37. {
  38. var random = new Random();
  39. double x = random.NextDouble() * random.Next();
  40. double y = random.NextDouble() * random.Next();
  41. double angle = random.NextDouble() * random.Next();
  42. var expectedResult = (AnglesToCoordinatesTask.GetJointPositions(ManipulatorTask.MoveManipulatorTo(x, y, angle)[0], ManipulatorTask.MoveManipulatorTo(x, y, angle)[1], ManipulatorTask.MoveManipulatorTo(x, y, angle)[2]))[2];
  43. var result = new PointF((float)x, (float)y);
  44. Assert.AreEqual(expectedResult, result);
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement