Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import sys
import traceback

# Instantiate a Generic Joystick using its Vendor ID, Product ID and Interface ID
# Use IDF/apps/hidScanner to assist with getting this information.
# In this example, we are creating a mapping for a
# Thrustmaster AVA Base: https://eshop.thrustmaster.com/en_us/ava-base.html
# with an F16 grip: https://eshop.thrustmaster.com/en_us/viper-hotas-add-on-grip.html
try:
device = trick.HidGenericJoystick( 0x044F, 0x0415, 0 )
device.thisown = 0
self.addMasterDevice( device )
except Exception as e:
print( "IDF init error:", traceback.format_exc() )
sys.exit(1)

# Create a SingleFlightController, including compositing X, Y, and Z from buttons
# use IDF/apps/decoder to assist with figuring out which buttons to use

# this grip does not have a twist so we'll use some buttons
twist = trick.CompositeInput()
twist.thisown = 0
twist.addInput( device.getButton(14) )
twist.addInput( device.getButton(12), -1 )

x = trick.CompositeInput()
x.thisown = 0
x.addInput( device.getButton(15) ) # the buttons vector is zero indexed
x.addInput( device.getButton(17), -1 )

y = trick.CompositeInput()
y.thisown = 0
y.addInput( device.getButton(18) )
y.addInput( device.getButton(16), -1 )

z = trick.CompositeInput()
z.thisown = 0
z.addInput( device.getButton(7) )
z.addInput( device.getButton(9), -1 )

controller = trick.SingleFlightController(
device.leftRightPivot,
device.forwardBackwardPivot,
twist,
x, y, z
)
controller.roll.setInverted( True )
controller.pitch.setInverted( True )
controller.thisown = 0 # don't forget this!!


# add controller to the InputDeviceManager
self.inputDeviceManager.controller = controller
18 changes: 18 additions & 0 deletions 3rdParty/trick/examples/SIM_python_generic/RUN_test/input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
trick.real_time_enable()
trick.exec_set_software_frame(0.1)

# import IDF's modules
import idf.config

# inherit from IDF's Configurator
class Configurator(idf.config.Configurator) :

# this method is abstract in the base class, and so we must override it
def addMasterDevice(self, device):

# Despite being abstract in the base class, this method is nevertheless implemented there.
# (It calls addInputDevice for you). Don't forget to call it!
super(Configurator, self).addMasterDevice(device)

# Instantiate a Configurator, passing it the IdfInputDeviceManager instance from the S_define.
configurator = Configurator(example, configFile="RUN_test/generic_hc_config.py")
99 changes: 99 additions & 0 deletions 3rdParty/trick/examples/SIM_python_generic/S_define
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include "sim_objects/default_trick_sys.sm"
#include "idf/IdfInputDeviceManager.sm"

##include <sstream>
##include <iomanip>

##include "sim_services/Executive/include/exec_proto.h"
##include "idf/SingleFlightController.hh"
##include "idf/Deadband.hh"

/**
* Demonstrates the use of IDF within a Trick simulation, using the Python
* class idf.config.Configurator to add a device at run-time. See
* RUN_test/input.py.
*/
class Example : public IdfInputDeviceManager {

public:

/**
* While other examples have declared devices here, we want to leave the
* choice of device up to the user this time. In this example, our only
* concern is the Controller.
*/

/**
* While devices represent physical hardware, a controller represents a
* virtual interface into a control system. This separation allows
* control system developers to program against a domain-specific interface
* independent of any particular device that might service that
* interface. It further ensures that only devices that have been
* specifically mapped to the interface may be assigned to service it.
*/
idf::SingleFlightController *controller;

Example() :
/**
* Call the base class constructor, specifying the period at which the
* updateDevices() job will be called. You can optionally specify the
* phase and class for this job as well. See IdfInputDeviceManager.sm
* for details.
*/
IdfInputDeviceManager(0.1),
controller(NULL) {
/**
* Nothing to see here!
* All of the configuration is done in the input file.
*/
}

/**
* If you want to perform some action after all devices have been updated,
* one possibility is overriding IdfInputDeviceManager's updateDevices()
* function. In this example, we just want to print the controller's
* normalized values to the console. Normalized values always fall in the
* range [-1, 1], with the extremes corresponing to the minimum and maximum
* raw values. 0 represents the "neutral" point. If you choose this method,
* be sure to call the base class version of the function or the devices
* will never be updated!
*
* Another option is to just declare another scheduled job and do your post-
* update logic there. This can be useful if you want the updateDevices()
* job and your post-update logic to run at different rates or have
* different phases or job classes.
*/
void updateDevices() {

// Don't forget to call the base class version!
IdfInputDeviceManager::updateDevices();

/**
* The controller pointer is assigned via the input file (see Configurator.addMasterDevice).
* If no such assignment was made, then there is no physical device connected to the
* computer. In this case, IDF would launch the Virtual Hand Controller if the
* idf.config.Configurator was instantiated with support for the VHC. This sim does not
* do so (see SIM_virtual_hand_controller for an example that does), so we terminate.
*/
if (!controller) {
exec_terminate("S_define", "This sim requires a physical device to be connected.");
}

bool blah = controller->isActive();

// Print the values.
std::cout << std::showpos << std::fixed << std::setprecision(2)

<< " Roll: " << controller->getRoll()
<< " Pitch: " << controller->getPitch()
<< " Yaw: " << controller->getYaw()
<< " X: " << controller->getX()
<< " Y: " << controller->getY()
<< " Z: " << controller->getZ()

<< std::endl;
}

};

Example example;
1 change: 1 addition & 0 deletions 3rdParty/trick/examples/SIM_python_generic/S_overrides.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../makefiles/core.mk
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ set(SRC_IDF
source/idf/EthernetWingMan.cpp
source/idf/Extreme3dPro.cpp
source/idf/FlightController.cpp
source/idf/GenericJoystick.cpp
source/idf/Gravis.cpp
source/idf/HidDevice.cpp
source/idf/HidDecoder.cpp
source/idf/HidGenericJoystick.cpp
source/idf/HagstromKEUSB36.cpp
source/idf/IndustrialProducts2.cpp
source/idf/IndustrialProducts3.cpp
Expand Down
1 change: 1 addition & 0 deletions apps/decoder/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
decoder
18 changes: 18 additions & 0 deletions apps/decoder/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
IDF_HOME := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/../..)
IDF_CONFIG := $(IDF_HOME)/bin/idf-config
IDF_BUILD_DIR := $(IDF_HOME)/build
IDF_LIB := $(IDF_BUILD_DIR)/libidf.a

CXXFLAGS += $(shell $(IDF_CONFIG) --cxxflags)
LDLIBS += $(shell $(IDF_CONFIG) --libs)

decoder: $(IDF_LIB)

$(IDF_LIB): | $(IDF_BUILD_DIR)
cd $| && cmake .. && $(MAKE)

$(IDF_BUILD_DIR):
mkdir -p $@

clean:
@rm -rf decoder
Loading