// Ensure the emitter is immediately disposed when destroyed void OnDestroy() { _emitter.Dispose(); _emitter = null; _alignment.Dispose(); _alignment = null; }
/// <summary> /// this function is to update the live rendering points which comes from ultraleap live rendering feature /// </summary> /// <param name="updated_x"> the new x coordinate</param> /// <param name="updated_y"> the new y coordinate</param> public static void updateLiveRenderPoint(float updated_x, float updated_y) { if (emitter != null) { Vector3 position = new Vector3((float)(updated_x * Ultrahaptics.Units.metres), (float)(updated_y * Ultrahaptics.Units.metres), (float)(0.20 * Ultrahaptics.Units.metres)); AmplitudeModulationControlPoint point = new AmplitudeModulationControlPoint(position, intensity, frequency); var points = new List <AmplitudeModulationControlPoint> { point }; emitter.update(points); Console.WriteLine(updated_x + " " + updated_y); } if (Stop) { try { emitter.update(new List <AmplitudeModulationControlPoint> { }); emitter.Dispose(); emitter = null; } catch (Exception e) { Console.WriteLine(e.Message); } Stop = false; return; } }
public static void Main(string[] args) { // Create an emitter, which connects to the first connected device AmplitudeModulationEmitter emitter = new AmplitudeModulationEmitter(); // Set the position of the new control point Vector3 position = new Vector3(0.0f, 0.0f, 0.2f); // Set how intense the feeling at the new control point will be float intensity = 1.0f; // Set the frequency of the control point, which can change the feeling of the sensation float frequency = 200.0f; // Define the control point AmplitudeModulationControlPoint point = new AmplitudeModulationControlPoint(position, intensity, frequency); var points = new List <AmplitudeModulationControlPoint> { point }; // Instruct the device to stop any existing actions and start producing this control point bool isOK = emitter.update(points); // The emitter will continue producing this point until instructed to stop // Wait until the program is ready to stop Console.ReadKey(); // Stop the emitter emitter.stop(); // Dispose/destroy the emitter emitter.Dispose(); emitter = null; }
// Use this for initialization void Start() { _amEmitter = new AmplitudeModulationEmitter(); _coordinateSpaceConverter = FindObjectOfType <CoordinateSpaceConverter>(); _hapticReceivers = _handsRoot.GetComponentsInChildren <HapticReceiver>(true); if (!_amEmitter.isConnected()) { Debug.LogWarning("No Ultrahaptics array connected"); } }
/// <summary> /// Starts the live ultrahaptics rendering /// Note: live ultrahaptics rendering of a point always happrns in AM and is never implemented in TPS /// </summary> public static void RenderLive() { Stop = false; emitter = new AmplitudeModulationEmitter(); Vector3 position = new Vector3((float)(0 * Ultrahaptics.Units.metres), (float)(0 * Ultrahaptics.Units.metres), (float)(0.20 * Ultrahaptics.Units.metres)); AmplitudeModulationControlPoint point = new AmplitudeModulationControlPoint(position, intensity, frequency); var points = new List <AmplitudeModulationControlPoint> { point }; emitter.update(points); }
public static void Render() { Stop = false; string file_name = Path.Combine(Environment.CurrentDirectory, "list.csv"); emitter = new AmplitudeModulationEmitter(); for (; ;) { using (TextFieldParser parser = new TextFieldParser(file_name)) { parser.TextFieldType = FieldType.Delimited; parser.SetDelimiters(","); while (!parser.EndOfData) { double x = 1000, y = 1000; //Processing row string[] fields = parser.ReadFields(); foreach (string field in fields) { //TODO: Process field if (x == 1000) { x = double.Parse(field); } else if (y == 1000) { y = double.Parse(field); } } Vector3 position = new Vector3((float)(x * Ultrahaptics.Units.metres), (float)(y * Ultrahaptics.Units.metres), (float)(0.20 * Ultrahaptics.Units.metres)); AmplitudeModulationControlPoint point = new AmplitudeModulationControlPoint(position, intensity, frequency); var points = new List <AmplitudeModulationControlPoint> { point }; emitter.update(points); //this condition will stop emitter from processing further if (Stop) { emitter.update(new List <AmplitudeModulationControlPoint> { }); emitter.Dispose(); emitter = null; Stop = false; return; } } } } }
public static void Main(string[] args) { // Width of the kit, refer to the User Guide of your device float width = 0.210f; // meters // affine transformation matrix placing the device half its width to the left in the global space Transform left_tr = new Transform(); left_tr.setOrigin(new Vector3(-width / 2, 0.0f, 0.0f)); // affine transformation matrix placing the device half its width to the right in the global space Transform right_tr = new Transform(); right_tr.setOrigin(new Vector3(width / 2, 0.0f, 0.0f)); // Create an emitter, which connects to the first connected device // Please make sure to use the correct identifiers for your devices AmplitudeModulationEmitter emitter = new AmplitudeModulationEmitter("USX:USX-00000000", left_tr); emitter.addDevice("USX:USX-00000001", right_tr); // Set the position of the new control point Vector3 position1 = new Vector3(-0.05f, 0.0f, 0.2f); Vector3 position2 = new Vector3(0.05f, 0.0f, 0.2f); // Set how intense the feeling at the new control point will be float intensity = 1.0f; // Set the frequency of the control point, which can change the feeling of the sensation float frequency = 200.0f; // Define the control point AmplitudeModulationControlPoint point1 = new AmplitudeModulationControlPoint(position1, intensity, frequency); AmplitudeModulationControlPoint point2 = new AmplitudeModulationControlPoint(position2, intensity, frequency); var points = new List <AmplitudeModulationControlPoint> { point1, point2 }; // Instruct the device to stop any existing actions and start producing this control point bool isOK = emitter.update(points); // The emitter will continue producing this point until instructed to stop // Wait until the program is ready to stop Console.ReadKey(); // Stop the emitter emitter.stop(); // Dispose/destroy the emitter emitter.Dispose(); emitter = null; }
void Start() { // Initialize the emitter _emitter = new AmplitudeModulationEmitter(); _emitter.initialize(); _leap = new Leap.Controller(); // NOTE: This example uses the Ultrahaptics.Alignment class to convert Leap coordinates to the Ultrahaptics device space. // You can either use this as-is for Ultrahaptics development kits, create your own alignment files for custom devices, // or replace the Alignment references in this example with your own coordinate conversion system. // Load the appropriate alignment file for the currently-used device _alignment = _emitter.getDeviceInfo().getDefaultAlignment(); // Load a custom alignment file (absolute path, or relative path from current working directory) // _alignment = new Alignment("my_custom.alignment.xml"); }
[Fact] public void Emit() { Data_Generator dg = new Data_Generator(); Hand_Generator hg = new Hand_Generator(dg); VectorHelper vh = new VectorHelper(); JointsHelper jh = new JointsHelper(vh); AmplitudeModulationEmitter mock_emitter = new AmplitudeModulationEmitter("MockDevice:U5;logfile=log.txt"); var j = hg.newJoints(); bool exp = false; bool act = false; var haptic = new Haptic(jh, mock_emitter); var point = haptic.AquireTarget(j); var points = new List <AmplitudeModulationControlPoint>(); points.Add(point); exp = mock_emitter.update(points); act = haptic.Emit(points); Assert.Equal(exp, act); }
public static void Main(string[] args) { // Create an emitter, which connects to the first connected device AmplitudeModulationEmitter emitter = new AmplitudeModulationEmitter(); // Create an aligment object which relates the tracking and device spaces Alignment alignment = emitter.getDeviceInfo().getDefaultAlignment(); // Create a Leap Contoller Controller controller = new Controller(); ButtonWidget button = new ButtonWidget(); // Set the position of the new control point Vector3 position = new Vector3(0.0f, 0.0f, 0.2f); // Set how intense the feeling at the new control point will be float intensity = 1.0f; // Set the frequency of the control point, which can change the feeling of the sensation float frequency = 200.0f; // Define the control point AmplitudeModulationControlPoint point = new AmplitudeModulationControlPoint(position, intensity, frequency); var points = new List <AmplitudeModulationControlPoint> { point }; // Wait for leap if (!controller.IsConnected) { Console.WriteLine("Waiting for Leap"); while (!controller.IsConnected) { System.Threading.Thread.Sleep(1000); Console.WriteLine("."); } Console.WriteLine("\n"); } controller.EnableGesture(Gesture.GestureType.TYPE_KEY_TAP); if (controller.Config.SetFloat("Gesture.Swipe.MinDistance", 30) && controller.Config.SetFloat("Gesture.Swipe.MinDownVelocity", 30) && controller.Config.SetFloat("Gesture.Swipe.MinSeconds", 0.01f)) { controller.Config.Save(); } bool button_on = true; new Stopwatch(); for (;;) { Frame frame = controller.Frame(); HandList hands = frame.Hands; if (!hands.IsEmpty && button_on) { Hand hand = hands[0]; for (int i = 0; i < frame.Gestures().Count; i++) { Gesture gesture = frame.Gestures()[i]; if (gesture.Type == Gesture.GestureType.TYPE_KEY_TAP) { button_on = false; emitter.stop(); break; } } position = new Vector3(hand.PalmPosition.x, hand.PalmPosition.y, hand.PalmPosition.z); Vector3 normal = new Vector3(-hand.PalmNormal.x, -hand.PalmNormal.y, -hand.PalmNormal.z); Vector3 direction = new Vector3(hand.Direction.x, hand.Direction.y, hand.Direction.z); Vector3 device_position = alignment.fromTrackingPositionToDevicePosition(position); Vector3 device_normal = alignment.fromTrackingDirectionToDeviceDirection(normal).normalize(); Vector3 device_direction = alignment.fromTrackingDirectionToDeviceDirection(direction).normalize(); Vector3 device_palm_x = device_direction.cross(device_normal).normalize(); device_position += (device_direction * MathF.Cos(button.angle) + device_palm_x * MathF.Sin(button.angle)) * button.radius; points[0].setPosition(device_position); // Instruct the device to stop any existing actions and start producing this control point emitter.update(points); // The emitter will continue producing this point until instructed to stop button.angle += 0.05f; button.angle = button.angle % (2.0f * PI); } else if (!hands.IsEmpty && !button_on) { emitter.stop(); for (int i = 0; i < frame.Gestures().Count; i++) { Gesture gesture = frame.Gestures()[i]; if (gesture.Type == Gesture.GestureType.TYPE_KEY_TAP) { button_on = true; emitter.stop(); break; } } } else { emitter.stop(); } System.Threading.Thread.Sleep(10); } // Dispose/destroy the emitter emitter.Dispose(); emitter = null; controller.Dispose(); }
public static void Main(string[] args) { // Create an emitter, which connects to the first connected device AmplitudeModulationEmitter emitter = new AmplitudeModulationEmitter(); Alignment alignment = emitter.getDeviceInfo().getDefaultAlignment(); Controller controller = new Controller(); MazeGame game = new MazeGame(); // Wait for leap if (!controller.IsConnected) { Console.WriteLine("Waiting for Leap"); while (!controller.IsConnected) { System.Threading.Thread.Sleep(1000); Console.WriteLine("."); } Console.WriteLine("\n"); } controller.EnableGesture(Gesture.GestureType.TYPE_KEY_TAP); Console.WriteLine("Leap controller connected."); var walls = Wall.GenWalls(game.current_cell); var recently_moved = false; for (;;) { for (int i = 0; i < walls.Count; i++) { Frame frame = controller.Frame(); HandList hands = frame.Hands; float z = 0.2f; if (!hands.IsEmpty) { Hand hand = hands[0]; for (int g = 0; g < frame.Gestures().Count; g++) { if (frame.Gestures() [g].State == Gesture.GestureState.STATE_STOP) { game.PickUpKey(); } } Vector3 pos = new Vector3(hand.PalmPosition.x, hand.PalmPosition.y, hand.PalmPosition.z); Vector3 normal = new Vector3(hand.PalmNormal.x, hand.PalmNormal.y, hand.PalmNormal.z); Vector3 palm_pos = alignment.fromTrackingPositionToDevicePosition(pos); Vector3 palm_normal = alignment.fromTrackingDirectionToDeviceDirection(normal).normalize(); float far_center = 0.7f; if (palm_normal.x > far_center && !recently_moved) { Console.WriteLine("Moving right!"); var cell = game.MoveTo('e'); walls = Wall.GenWalls(cell); recently_moved = true; break; } if (palm_normal.x < -far_center && !recently_moved) { Console.WriteLine("Moving left!"); var cell = game.MoveTo('w'); walls = Wall.GenWalls(cell); recently_moved = true; break; } if (palm_normal.y < -far_center && !recently_moved) { Console.WriteLine("Moving down!"); var cell = game.MoveTo('s'); walls = Wall.GenWalls(cell); recently_moved = true; break; } if (palm_normal.y > far_center && !recently_moved) { Console.WriteLine("Moving up!"); var cell = game.MoveTo('n'); walls = Wall.GenWalls(cell); recently_moved = true; break; } if (palm_normal.z < -0.8f && recently_moved) { recently_moved = false; } z = palm_pos.z; } // Instruct the device to stop any existing actions and start producing this control point bool isOK = emitter.update(walls[i].GetPoints(z)); System.Threading.Thread.Sleep(10); } } // The emitter will continue producing this point until instructed to stop // // Wait until the program is ready to stop // Console.ReadKey(); // // Stop the emitter // emitter.stop(); // // Dispose/destroy the emitter // emitter.Dispose(); // emitter = null; }
public Haptic(JointsHelper hand, AmplitudeModulationEmitter emitter) { jh = hand; ee = emitter; }
// Ensure the emitter is immediately disposed when destroyed void OnDestroy() { _emitter.Dispose(); _emitter = null; }
void Start() { // Initialize the emitter _emitter = new AmplitudeModulationEmitter(); _emitter.initialize(); }
public static void Main() { Thread newWindowThread = new Thread(new ThreadStart(() => { // create and show the window App obj = new App(); // start the Dispatcher processing System.Windows.Threading.Dispatcher.Run(); })); newWindowThread.SetApartmentState(ApartmentState.STA); newWindowThread.IsBackground = true; newWindowThread.Start(); while (!GBL.DONE_EDITING) { System.Threading.Thread.Sleep(1000); } // Connect to LeapMotion Controller Console.WriteLine("Initializing Leap..."); var leapMotion = new Controller(); do { System.Threading.Thread.Sleep(1000); Console.WriteLine("."); } while (!leapMotion.IsConnected); Console.WriteLine("Leap ready."); // Connect to UHDK5 ultrasonic emitters Console.WriteLine("Initializing UHDK5..."); var uhdk5 = new AmplitudeModulationEmitter(); Console.WriteLine("UHDK5 ready."); Console.WriteLine("Dog Friendly Mode: " + GBL.DOG_FRIENDLY); // Connect virtual MIDI ports Console.WriteLine("Initializing virtual MIDI ports..."); MIDI.logging(MIDI.TE_VM_LOGGING_MISC | MIDI.TE_VM_LOGGING_RX | MIDI.TE_VM_LOGGING_TX); var leftManu = new Guid("aa4e075f-3504-4aab-9b06-9a4104a91cf0"); var leftProd = new Guid("bb4e075f-3504-4aab-9b06-9a4104a91cf0"); var leftMIDI = new MIDI("Air Drums Left Hand", 65535, MIDI.TE_VM_FLAGS_PARSE_RX, ref leftManu, ref leftProd); var rightManu = new Guid("cc4e075f-3504-4aab-9b06-9a4104a91cf0"); var rightProd = new Guid("dd4e075f-3504-4aab-9b06-9a4104a91cf0"); var rightMIDI = new MIDI("Air Drums Right Hand", 65535, MIDI.TE_VM_FLAGS_PARSE_RX, ref rightManu, ref rightProd); Console.WriteLine("MIDI resources ready."); // Haptics resources var hapticTargets = new List <AmplitudeModulationControlPoint>(); var hapticTimes = new List <int>(); var hapticVH = new VectorHelper(); var hapticJH = new JointsHelper(hapticVH); var haptic = new Haptic(hapticJH, uhdk5); // MIDI resources var leftComTable = new Commands(true); var leftNotes = new List <int>(); var leftTimes = new List <int>(); var leftPort = new Port(leftMIDI); var rightComTable = new Commands(false); var rightNotes = new List <int>(); var rightTimes = new List <int>(); var rightPort = new Port(rightMIDI); // Classification resources var leftVH = new VectorHelper(); var leftJH = new JointsHelper(leftVH); var leftStats = new Stats(leftJH); var leftClassify = new Classify(leftVH, leftStats); var leftQueues = new Queues(leftJH); var leftDataManager = new DataManager(leftQueues, true); var rightVH = new VectorHelper(); var rightJH = new JointsHelper(rightVH); var rightStats = new Stats(rightJH); var rightClassify = new Classify(rightVH, rightStats); var rightQueues = new Queues(rightJH); var rightDataManager = new DataManager(rightQueues, false); // Concurrency structures var leftFrameStream = new ConcurrentQueue <Frame>(); var leftCommandStream = new ConcurrentQueue <int>(); var rightFrameStream = new ConcurrentQueue <Frame>(); var rightCommandStream = new ConcurrentQueue <int>(); var hapticStream = new ConcurrentQueue <Joints>(); // Processes var data = new Proc_Data(leapMotion, leftFrameStream, rightFrameStream) as IProc; var leftGesture = new Proc_Gesture(leftClassify, leftDataManager, leftVH, leftFrameStream, leftCommandStream, hapticStream) as IProc; var leftCommand = new Proc_MIDI(leftPort, leftCommandStream, leftNotes, leftTimes, leftComTable) as IProc; var rightGesture = new Proc_Gesture(rightClassify, rightDataManager, rightVH, rightFrameStream, rightCommandStream, hapticStream) as IProc; var rightCommand = new Proc_MIDI(rightPort, rightCommandStream, rightNotes, rightTimes, rightComTable) as IProc; var haptics = new Proc_Haptics(haptic, hapticStream, hapticTargets, hapticTimes) as IProc; // Instantiate threads with looped pipelines var dataThread = new Thread(data.Loop); var leftGestureThread = new Thread(leftGesture.Loop); var rightGestureThread = new Thread(rightGesture.Loop); var leftCommandThread = new Thread(leftCommand.Loop); var rightCommandThread = new Thread(rightCommand.Loop); var hapticsThread = new Thread(haptics.Loop); // Start threads dataThread.Start(); leftGestureThread.Start(); rightGestureThread.Start(); leftCommandThread.Start(); rightCommandThread.Start(); hapticsThread.Start(); }