-
Notifications
You must be signed in to change notification settings - Fork 35
Virtual Hand Controller
The Virtual Hand Controller is a Java application that provides a basic six degree-of-freedom device, useful when you don't have any physical devices available. There are a few things you'll need to do to enable support for it in your simulation.
The VHC requires at least Java SE 8.
Like all devices, the VHC's input layout is represented by a class in the Input Abstraction Layer. Specifically, include/VirtualLayout.hh
. This class contains the fields that the VHC writes to via Trick's Variable Server. Your sim needs to contain an instance of this class so that the VHC has somewhere to send its values. To do so, simply declare a variable of the appropriate type anywhere in your sim, and name it whatever you like. For instance, the example sims (in 3rdParty/trick/examples
) declare it in their S_define
s like so:
idf::VirtualLayout virtualLayout;
The VHC can be launched manually or automatically and from C++, Python, or the command line. Regardless of the method, you must tell the VHC the name of your VirtualLayout
instance so it knows where to write its values. The name must be the full path starting from the top-most containing variable. In the example sims, the instance is contained within an instance named example
, so the path is example.virtualLayout
. If you had code like this:
class Bar {
idf::VirtualLayout baz;
};
class Foo {
Bar bar;
};
Foo foo;
The path would then be foo.bar.baz
.
If you're already using idf.config.Configurator, simply providing the vhcVariableName
argument when constructing it will cause IDF to automatically launch the VHC when no physical devices are found. If you're just getting started and don't want to bother with the additional infrastructure that requires, it's equally easy to launch the VHC manually.
To launch IDF from the input file, simply import IDF's Python module and call the launch function, providing the name of your VirtualLayout
instance:
import idf.config
idf.config.launchVirtualController("example.virtualLayout")
You don't need to mess with sys.path
if you're in Trick 15.3 or 17.1 or later. Otherwise, you'll need something like this first:
sys.path.append(os.environ['IDF_HOME'] + "/3rdParty/trick/python")
IDF_HOME
will be set automatically if you include IDF's Sim Makefile from your S_overrides.mk
. See 3rdParty/trick/examples/SIM_virtual_hand_controller_python
for an example.
I really recommend using the Python method since it's so simple. You can launch the VHC from C++ code as well, but it takes more work, and I don't see any obvious benefits. Nevertheless, 3rdParty/trick/examples/SIM_virtual_hand_controller
illustrates how to do it using Trick's application-launching framework.
Finally, it's just a Java app, so you can run it straight from the command line if you like!
java -jar apps/vhc/build/VirtualHandController.jar
Again, you'll have to pass the name of your VirtualLayout
as an argument via the --name
option. There are a bunch of other options, too. Pass --help
to get a list.