OpenHaptics编程环境搭建

本文介绍了SensAble Technologies的PHANTOM系列触觉交互设备及其OpenHaptics Toolkit,用于创建力反馈应用。详细阐述了在Win7 64位系统+VS2013上搭建编程环境的步骤,包括设备驱动安装、VS工程配置以及解决编译错误的方法。同时,讨论了OpenHaptics的HDAPI编程,包括力反馈帧、同步与异步调用、回调函数的返回值和任务优先级,提供了获取设备信息的示例。
摘要由CSDN通过智能技术生成

  SensAble Technologies公司是3D可触摸(力反馈)解决方案和技术领域中的领先开发商,其解决方案和技术不仅使用户能够看到并听到屏幕计算机应用,还可以对该应用进行实际“感应”。该公司的PHANTOM系列触觉与力反馈交互设备能使用户接触并操作虚拟物体。其触觉技术广泛应用于诸多领域,包括外科手术模拟、牙科整形、虚拟装配与虚拟维修、3D 设计(艺术和雕塑),以及机器人遥操作等领域。

  使用官方提供的OpenHaptics Toolkit可以方便的编写基于Phantom触觉力反馈设备的应用程序。OpenHaptics工具包包括QuickHaptics Micro API、Haptic Device API(HDAPI)、Haptic Library API (HLAPI)、PHANTOM Device Drivers(PDD)、实用工具和源代码示例。最底层的是PDD设备驱动程序,它支持公司所有系列的力反馈设备;HDAPI提供了一个底层接口,通过它能直接产生反馈力以及获取设备的状态信息;HLAPI则为熟悉OpenGL的编程人员提供了一个上层接口。

  下面来搭建OpenHaptics的编程环境(Win7 64位系统 + VS2013 + OpenHaptics 3.4.0),先在这里下载设备驱动程序和OpenHaptics Toolkit。参考安装手册连接好电脑和Phantom设备后可以打开官方自带的Phantom Test程序进行测试,验证设备是否连接成功。

 

  接下来使用HDAPI创建一个力反馈应用程序(以examples\HD\console\HelloHapticDevice为例),程序基本流程如下:

  1.  Initialize the device.

  2.  Create a scheduler callback.

  3.  Enable device forces.

  4.  Start the scheduler.

  5.  Cleanup the device and scheduler when the application is terminated. 

  参考下面的程序结构图,为了实现流畅稳定的触觉力反馈,创建的任务将以1000Hz的频率运行在优先级高的线程中(The scheduler manages a high frequency, high priority thread for sending forces and retrieving state information from the device. Typically, force updates need to be sent at 1000 Hz frequency in order to create compelling and stable force feedback):

  下面配置VS工程:

  1)设置头文件包含目录(Set the correct include path, as shown below in “Additional Include Directories.”)

  Examples for setting include paths:

  $(OH_SDK_BASE)\include                     Main include directory for the HD library.
  $(OH_SDK_BASE)\utilities\include         Include directory for utilities.

  2)添加库文件(Add the appropriate library modules as shown below in “Additional Dependencies”)

   3)设置附加库目录(Make sure the linker paths are set correctly on the “Additional Library Directories” line so that the library fles can be found whenyour application links

  As for the header fle include paths, the library directories will use the OH_SDK_BASE environment variable. In general VisualStudio will automatically set the PlatformName to be one of Win32 or x64 and the ConfgurationName to be either Release or Debug. 

 

  配置好工程属性后就可以点击生成按钮,不过生成过程中出现了“error LNK2019:无法解析的外部符号”这种错误(很多人遇到过这个问题):

  在网上搜索解决方案,3DSystems Haptics Forums有一种办法是将utilities中的lib文件重新编译一遍,源文件就在utilities/src中:

  使用VS013重新生成Win32、x64平台下的Debug和Release版本的lib,然后将原先的替换掉,再进行编译就OK了。

 

 


   下面看看HelloHapticDevice的代码:

/*****************************************************************************
Description: 

  This application creates a gravity well, which will attract
  the device towards its center when the device enters its proximity.  
*******************************************************************************/

#include <stdio.h>
#include <string.h>
#include <conio.h>

#include <HD/hd.h>
#include <HDU/hduError.h>
#include <HDU/hduVector.h>

HDCallbackCode HDCALLBACK gravityWellCallback(void *data);


/*******************************************************************************
 Main function.
 Initializes the device, starts the schedule, creates a schedule callback
 to handle gravity well forces, waits for the user to press a button, exits
 the application.
*******************************************************************************/
int main(int argc, char* argv[])
{    
    HDErrorInfo error;
    HDSchedulerHandle hGravityWell;

    /* Initialize the device, must be done before attempting to call any hd 
       functions. Passing in HD_DEFAULT_DEVICE causes the default device to be 
       initialized. */
    HHD hHD = hdInitDevice(HD_DEFAULT_DEVICE);
    if (HD_DEVICE_ERROR(error = hdGetError())) 
    {
        hduPrintError(stderr, &error, "Failed to initialize haptic device");
        fprintf(stderr, "\nPress any key to quit.\n");
        return -1;
    }

    printf("Hello Haptic Device!\n");
    printf("Found device model: %s.\n\n", hdGetString(HD_DEVICE_MODEL_TYPE));

    /* Schedule the main callback that will render forces to the device. 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值