static void Main(string[] args) { uint hHD = HDAPI.hdInitDevice(null); HDAPI.hdEnable(HDEDParameters.HD_FORCE_OUTPUT); HDAPI.hdStartScheduler(); HDErrorInfo error = HDAPI.hdGetError(); if (error.CheckedError()) { Console.WriteLine("Start Scheduler Failed."); Console.ReadKey(); return; } ulong pHandler = HDAPI.hdScheduleAsynchronous(FrictionlessSphereCallback, IntPtr.Zero, HDSchedulerPriority.HD_DEFAULT_SCHEDULER_PRIORITY); while (true) { if (HDAPI.hdWaitForCompletion(pHandler, HDWaitCode.HD_WAIT_CHECK_STATUS) == 0x00) { Console.WriteLine("主回调器退出。"); Console.ReadKey(); return; } } HDAPI.hdStopScheduler(); HDAPI.hdUnschedule(pHandler); HDAPI.hdDisableDevice(hHD); }
static void Main(string[] args) { uint hHD = HDAPI.hdInitDevice("Default Device"); error = HDAPI.hdGetError(); if (error.CheckedError()) { Console.WriteLine("Device Initialize Failed.."); Console.ReadKey(); return; } //HDSchedulerCallback pCallback = GravityWellCallback; ulong gravityWell = HDAPI.hdScheduleAsynchronous(GravityWellCallback, IntPtr.Zero, HDSchedulerPriority.HD_MAX_SCHEDULER_PRIORITY); HDAPI.hdEnable(HDEDParameters.HD_FORCE_OUTPUT); HDAPI.hdStartScheduler(); error = HDAPI.hdGetError(); if (error.CheckedError()) { Console.WriteLine("Start Scheduler Failed.."); Console.ReadKey(); return; } while (true) { ConsoleKeyInfo key = Console.ReadKey(); if (key.Key == ConsoleKey.DownArrow) { InForce = true; Console.WriteLine("In Force:{0}", true); } else if (key.Key == ConsoleKey.UpArrow) { InForce = false; Console.WriteLine("Out Force:{0}", false); } if (HDAPI.hdWaitForCompletion(gravityWell, HDWaitCode.HD_WAIT_CHECK_STATUS) == 0x00) { Console.WriteLine("Ready quit.."); Console.ReadKey(); break; } } HDAPI.hdStopScheduler(); HDAPI.hdUnschedule(gravityWell); HDAPI.hdDisableDevice(hHD); }
static void Main(string[] args) { uint hHD = HDAPI.hdInitDevice(HDAPI.HD_DEFAULT_DEVICE); error = HDAPI.hdGetError(); if (error.CheckedError()) { Console.WriteLine("Device Initialize Failed.."); return; } //更新校准 //HDAPI.hdUpdateCalibration(HDCalibrationStyles.HD_CALIBRATION_INKWELL); HDSchedulerCallback pCallback = AnchoredSpringForceHandler; IntPtr deviceHHD = new IntPtr(hHD); ulong pHandler = HDAPI.hdScheduleAsynchronous(pCallback, deviceHHD, HDSchedulerPriority.HD_MAX_SCHEDULER_PRIORITY); //启用力输出功能 HDAPI.hdEnable(HDEDParameters.HD_FORCE_OUTPUT); double maxStiffness = 0; //查询设备能够处理的最大闭环控制刚度。使用超过这个限制的值可能会导致设备嗡嗡作响。 HDAPI.hdGetDoublev(HDGetParameters.HD_NOMINAL_MAX_STIFFNESS, ref maxStiffness); HDAPI.hdStartScheduler(); error = HDAPI.hdGetError(); if (error.CheckedError()) { Console.WriteLine("启动调度程序失败."); Console.ReadKey(); return; } Console.WriteLine("按下 Button 1 开始,按上下键设置 force 值"); while (true) { ConsoleKeyInfo key = Console.ReadKey(true); if (key.Key == ConsoleKey.DownArrow) { gSpringStiffness -= 0.05; if (gSpringStiffness <= 0) { gSpringStiffness = 0.00; } Console.WriteLine("gSpringStiffness:{0}", gSpringStiffness); } else if (key.Key == ConsoleKey.UpArrow) { gSpringStiffness += 0.05; if (gSpringStiffness >= maxStiffness) { gSpringStiffness = maxStiffness; } Console.WriteLine("gSpringStiffness:{0}", gSpringStiffness); } } HDAPI.hdStopScheduler(); HDAPI.hdUnschedule(pHandler); HDAPI.hdDisableDevice(hHD); }