Driving With An Xbox Controller in Dymola

There are many ways to control a vehicle in Dymola. This includes constraining it in a rig, using a closed loop driver model or defining open loop controls. But if you want to use it in a Driver-In-The-Loop scenario then the VeSyMA-DiL library will allow you to do that. This library will allow you to control a vehicle with all the controls and it interfaces with rFpro that provides the virtual environment; and can control a 6 Axis rig to have a complete simulator interface.

However, there is a library called DeviceDrivers, shipped with Dymola, that lets models be controlled using external controls. This will allow any model that runs in real time to be controlled by the user. Control can be either through a keyboard, joystick or my personal preference being a gaming controller. In early stages of development, or when investigating effects that require interactive control, this can make testing a lot easier.

Creating the interface

I wanted to test a vehicle (and my ability to control it) in real time and without access to a steering wheel or full simulator. I reached for my old Xbox 360 controller.

The DeviceDrivers library includes multiple blocks for different types of inputs. I used the Joystick Input block that allows both button and variable axis inputs. This is very important as I need steering, accelerator and brake inputs to be variable.

After a bit of trial and error to find the controller mapping that felt most comfortable I was able to get all the controls for a manual vehicle working. The interfacing would all be held in a driver model, meaning only one model needed changing to get it all to work.

Figure 1: Driver model with the controller interface
Figure: Driver model with the controller interface

This interface allowed just the replacement of the driver model to be able to control any vehicle model. The longitudinal vehicle models in the VeSyMA Library were easy to control, as they are all longitudinal. Then the vehicle model, taken directly from VeSyMA – Suspensions was used.

Full Vehicle Real Time Simulation

Once the simulation was running it was a matter of getting the animation running and following the vehicle. Once that was set up, I was able to control the vehicle with only a small amount of delay between the inputs and the animation.

Video: Attempt at a Figure Eight with an Xbox controller

Unfortunately there was no perspective applied in the Dymola animation window making depth perception quite challenging and judging speed extremely difficult. But after a bit of practice I was able to make at least half of the Figure Eight. The Suspensions Closed loop driver was able to make a much better attempt at it.

It turns out that while getting an Xbox controller to control a vehicle is relatively easy to set up; using the Xbox controller to control the vehicle in Dymola does result in a few challenges. While it did allow me to carry out many basic tests, unfortunately I think this particular application may be a little out of the league of Xbox controllers and the Dymola animation window.

Having said this, the use of the DeviceDrivers library offered a very good interactive real time interface to simulations.

Written by: David Briant – Project Engineer

Please get in touch if you have any questions or have got a topic in mind that you would like us to write about. You can submit your questions / topics via: Tech Blog Questions / Topic Suggestion


Got a question? Just fill in this form and send it to us and we'll get back to you shortly.


© Copyright 2010-2024 Claytex Services Ltd All Rights Reserved

Log in with your credentials

Forgot your details?