AdmittanceModule.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using RUSCommon;
  2. using System;
  3. using System.Runtime.InteropServices;
  4. namespace AdmittanceModuleLib
  5. {
  6. public class AdmittanceModule : IAdmittanceModule
  7. {
  8. #region dll import
  9. [DllImport("AdmittanceControl.dll", CallingConvention = CallingConvention.Cdecl)]
  10. private static extern void CreateAdmittanceControl(out IntPtr hAdmittanceControl);
  11. [DllImport("AdmittanceControl.dll", CallingConvention = CallingConvention.Cdecl)]
  12. private static extern void ReleaseAdmittanceControl([In] IntPtr hAdmittanceControl);
  13. [DllImport("AdmittanceControl.dll", CallingConvention = CallingConvention.Cdecl)]
  14. private static extern void SetAdmittanceControl([In] IntPtr hAdmittanceControl, EnumAdmittanceSpace admittanceSpace, EnumAdmittanceType admittanceType);
  15. [DllImport("AdmittanceControl.dll", CallingConvention = CallingConvention.Cdecl)]
  16. private static extern void UpdateCurrentForce([In] IntPtr hAdmittanceControl, FTData force);
  17. [DllImport("AdmittanceControl.dll", CallingConvention = CallingConvention.Cdecl)]
  18. private static extern void UpdateCurrentWayPoint([In] IntPtr hAdmittanceControl, RobotWayPointData wayPoint);
  19. [DllImport("AdmittanceControl.dll", CallingConvention = CallingConvention.Cdecl)]
  20. private static extern void UpdateReferWayPoint([In] IntPtr hAdmittanceControl, RobotWayPointData wayPoint);
  21. [DllImport("AdmittanceControl.dll", CallingConvention = CallingConvention.Cdecl)]
  22. private static extern void GetTargetWayPoint([In] IntPtr hAdmittanceControl, ref RobotWayPointData wayPoint);
  23. #endregion
  24. #region private variable
  25. private static IntPtr _admittanceControlHandle = IntPtr.Zero;
  26. #endregion private variable
  27. #region 实现
  28. public void Dispose()
  29. {
  30. if (_admittanceControlHandle != IntPtr.Zero)
  31. {
  32. ReleaseAdmittanceControl(_admittanceControlHandle);
  33. _admittanceControlHandle = IntPtr.Zero;
  34. }
  35. }
  36. public void SetAdmittance(EnumAdmittanceSpace admittanceSpace, EnumAdmittanceType admittanceType)
  37. {
  38. SetAdmittanceControl(_admittanceControlHandle, admittanceSpace, admittanceType);
  39. }
  40. public void UpdateRealTimeForce(FTData ftdata)
  41. {
  42. UpdateCurrentForce(_admittanceControlHandle, ftdata);
  43. }
  44. public void UpdateRealTimeCurWayPt(RobotWayPointData currentWayPt)
  45. {
  46. UpdateCurrentWayPoint(_admittanceControlHandle, currentWayPt);
  47. }
  48. public void UpdateReferTargetWayPt(RobotWayPointData referWayPt)
  49. {
  50. UpdateReferWayPoint(_admittanceControlHandle, referWayPt);
  51. }
  52. public void GetActualTargetWayPt(ref RobotWayPointData targetWayPt)
  53. {
  54. GetTargetWayPoint(_admittanceControlHandle, ref targetWayPt);
  55. }
  56. public void StopAdmittanceControl()
  57. {
  58. Dispose();
  59. }
  60. #endregion 实现
  61. #region consdtuctor
  62. public AdmittanceModule()
  63. {
  64. if (_admittanceControlHandle == IntPtr.Zero)
  65. {
  66. CreateAdmittanceControl(out _admittanceControlHandle);
  67. }
  68. }
  69. #endregion consdtuctor
  70. }
  71. }