1 import com.bcu.userlab.haptics.*;

    2 import com.uce.userlab.haptics.DeviceException;

    3 

    4 public class JTouchMinimal {

    5 

    6     public static void main(String[] args) {

    7 

    8         // maximum radius of a device

    9         double maxRadius = 0.05;

   10 

   11         // maximum force sent to a device

   12         double maxForce = 10.0;

   13 

   14         HapticDevice hapticDevice = null;

   15 

   16         int numFalconDevices = 0;

   17 

   18         try

   19         {

   20             // get number of Novint Falcon Devices

   21 

   22             // calls FATAL ERROR - EXCEPTION_ACCESS_VIOLATION

   23             // Windows 7 64-bit, no falcon device

   24             // works fine on 32-bit system

   25             numFalconDevices = FalconDevice.countDevices();

   26         }

   27         catch (Exception e)

   28         {

   29             System.out.println("Error getting device count");

   30             System.exit(1);

   31         }

   32 

   33         // Print number of Novint Falcon devices

   34         System.out.println("Number of devices: " + numFalconDevices);

   35 

   36         // initialize Novint Falcon device

   37         if (numFalconDevices > 0)

   38         {

   39             try

   40             {

   41                 hapticDevice = FalconDevice.newFalconDevice(0);

   42             }

   43             catch (DeviceException deviceException)

   44             {

   45                 System.out.println("Error initializing device: " + deviceException.getMessage());

   46             }

   47         }

   48         else

   49         {

   50             System.exit(0);

   51         }

   52 

   53         if (hapticDevice == null) System.exit(1);

   54 

   55         System.out.println("hapticDevice.getDevice() = " + hapticDevice.getDevice());

   56         System.out.println("hapticDevice.getDeviceID() = " + hapticDevice.getDeviceID());

   57         System.out.println("hapticDevice.getVendor() = " + hapticDevice.getVendor());

   58         System.out.println("hapticDevice.getVersion() = " + hapticDevice.getVersion());

   59 

   60         System.out.println("hapticDevice.getMaxPositiveForce() = " + hapticDevice.getMaxPositiveForce());

   61         System.out.println("hapticDevice.getMaxNegativeForce() = " + hapticDevice.getMaxNegativeForce());

   62 

   63         System.out.println("FalconDevice.DEFAULT_FORCE_RAMPING_RATE = " + FalconDevice.DEFAULT_FORCE_RAMPING_RATE);

   64 

   65         // Add Haptic Listener

   66         MyNovintFalconHapticListener myHapticListener = new MyNovintFalconHapticListener();

   67 

   68         try

   69         {

   70             hapticDevice.addHapticListener(myHapticListener);

   71         }

   72         catch (DeviceException deviceException)

   73         {

   74             System.out.println(deviceException.getMessage());

   75             System.exit(1);

   76         }

   77 

   78 

   79         System.out.println("Press any button on Novint Falcon device to exit... starting in 1 second");

   80 

   81         try

   82         {

   83             Thread.sleep(1000);

   84         }

   85         catch (InterruptedException interruptedException)

   86         {

   87             // shouldn't happen

   88         }

   89 

   90 

   91         double lastPosition[] = new double[3];

   92         double force[] = new double[3];

   93 

   94         // while not button pressed

   95         while(myHapticListener.getLastNonNullInputState() == 0)

   96         {

   97             double position[] = hapticDevice.getCurrentPosition();

   98 

   99             if (lastPosition[0] != position[0] || 

  100                 lastPosition[1] != position[1] ||

  101                 lastPosition[2] != position[2])

  102             {

  103                 lastPosition = position;

  104 

  105                 double dforce[] = hapticDevice.getForce();

  106 

  107                 force[0] = -position[0] * 100;

  108                 force[1] = -position[1] * 100;

  109                 force[2] = -position[2] * 100;

  110 

  111                 hapticDevice.sendForce(force);

  112 

  113                 System.out.format("%.4f %.4f %.4f \t %.4f  %.4f  %.4f %n", position[0], position[1], position[2], dforce[0], dforce[1], dforce[2]);

  114             }

  115         }

  116 

  117         System.out.println("Button pressed - exit.");

  118     }

  119 }