Cafu for simulation question

Get help with installing and running the Cafu Engine here. This forum is also for general questions and discussion of all aspects regarding the Cafu Engine.
Post Reply
Sacramento
Posts:9
Joined:2013-08-30, 19:37
Cafu for simulation question

Post by Sacramento » 2013-08-30, 19:52

Hello, My name is Sacramento from Mexico, im an systems enginer student and im working with cafu for a project with the objective of making a warbout simulator machine for military purposes (training).

My question is, ¿How can we conect the cafu engine program with our external hardware devices (example, levers,lcd monitors, bottoms, microcontrollers) and make them control mechatronics systems with events by software programing.


I hope i could get a quick answer and thank you for your time if you read this.

Apologize if my english is too bad.
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Re: Cafu for simulation question

Post by Carsten » 2013-09-01, 21:05

Hi Sacramento,
welcome to the Cafu forums! :welcome:
¿How can we conect the cafu engine program with our external hardware devices (example, levers,lcd monitors, bottoms, microcontrollers) and make them control mechatronics systems with events by software programing.
Sorry for the late reply!
I'm a bit confused about the nature of your question: How the external hardware is controlled is obviously subject to the API that comes with and is specific to that hardware.
Using it from within the Cafu Engine thus means to employ that hardware's API from the places in the Cafu code where the data values that you want to relay to the hardware are readily available.
Or did I somehow misunderstand your question?
Best regards,
Carsten
Sacramento
Posts:9
Joined:2013-08-30, 19:37

Re: Cafu for simulation question

Post by Sacramento » 2013-09-02, 23:16

well thank you very much for the answer.

ok lets see an example...

I want to use a push-bottom device instead of my key board character W to move the entity in the cafu engine.

i mean i want to replace the hardware controls of the engine like the keyboard for external push-bottoms, the mouse for a lever(like the joystick).

conect this hardware...

Image

with the cafu engine controls, of course we are gonna build our own custom panel, but i want to test the programing events with electronic microcontrolers and making them to turn on leds in respond of the software for testing porpuses.

but i want to know, ¿how? ¿how can i do this? ¿it is possible with cafu? and if it is, ¿ how can i technical do it?

im sorry for my bad redaction. i hope i did express my self this time.
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Re: Cafu for simulation question

Post by Carsten » 2013-09-04, 00:32

Ok, so let's get more specific:

First, I assume that you're developing your software and running Cafu under Windows. If you're using Linux instead, please let me know.

Under Windows, Cafu uses the normal WIN32 API in order to receive mouse and keyboard events that it forwards to the appropriate program parts. For example, moving the mouse left triggers the related OS mouse events that we use either to move a mouse pointer image if a GUI is active, or to rotate the players view so that he or she can look around if we're in the game.

This approach is “complete” from the perspective of the Cafu code (and Windows code), except that it is lacking support for “advanced” input devices, such as joysticks. Support for such devices is the realm of DirectX, or - more portably - the SDL library. That is, before joysticks can be used with Cafu, the current event handling code had to augmented by DirectX or SDL first. (But note that besides the fact that joysticks require another program library, principally they're really completely alike to keyboards and mice: They're all input devices that triggers events when the user does something, that's really all there is.)

The next step would be to physically assemble the cockpit of your air, water or land vehicle. This step is totally unrelated to the Cafu Engine itself, but you'd probably purchase cheap keyboards, mice and joysticks that you can physically modify, or somehow else tune or twist or build into more appropriate, “original“ cockpit switches and controls.

Once complete, you have a cockpit that looks as you desire, but (invisible to the user) uses conventional input hardware under the hood.
For the perspective of the Cafu Engine, the input devices look like and other input devices look as well -- Cafu will never know if your users are sitting in a full-featured and fully styled cockpit or if they're using plain old PC hardware.


So far, this is how I understood your question. I believe that you probably only have trouble with one or a few of these steps, not with all of them. But as I'm unsure which is which, I hope that my above summary covers your issue? ;-)
Best regards,
Carsten
Sacramento
Posts:9
Joined:2013-08-30, 19:37

Re: Cafu for simulation question

Post by Sacramento » 2013-09-04, 01:04

:) thank you very much for the answer.
edit:
i have 3 questions so im gonna put them in order

1- ¿it is posible to conect an arduino or other kind of microcontroler?

2- this one is about cafu programing enviroment, if we can control what happen inside the map, like run, jump or using weapons and , ¿how could we trigger events that return a value?

example: im making a race like game, with a road where a car must be in all the times, if the car ( or whatever model we use) get out of the road ( it can be a brezier patch object or another form of limit). how cafu can deliver us a return message by saying something like "hey wrong way, go back to the road".

this is what i mean with a return value, in this case, the event its the car that is running out of the road, i want something from cafu that return a value from this event in respond.

3- we just bought a virtual reality glasses that we want to use with our simulator.

Image

¿can we use it within our cafu project in exchange of a mouse controller?

again thank you very much for all the help and kindness.
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Re: Cafu for simulation question

Post by Carsten » 2013-09-06, 10:37

Hi,
Sacramento wrote: 1- ¿it is posible to conect an arduino or other kind of microcontroler?
Yes, I think so.
I don't have an Arduino, but I just read that it supports USB natively, and can act as a mouse or a keyboard from the view of the PC it is connected to.
If programmed like this, it seems as if the Arduino can be used with Cafu even without altering the Cafu code (although such alterations may be helpful) -- simply because Cafu continues to believe that a standard mouse or keyboard is providing the input, when really an Arduino is connected.

2- this one is about cafu programing enviroment, if we can control what happen inside the map, like run, jump or using weapons and , [...]
how cafu can deliver us a return message by saying something like "hey wrong way, go back to the road".
this is what i mean with a return value, in this case, the event its the car that is running out of the road, i want something from cafu that return a value from this event in respond.
To be honest, I don't know.
I would imagine that the Arduino documentation has code examples that demonstrate how a PC can communicate with the Arduino when the Arduino does not act as a standard mouse or keyboard, so that the communication can be bi-directional and more flexible.

In this case, the situation would be somewhat analog to the situation with joysticks:
There is no built-in support in Cafu for such devices right now, but similar to the way you have to add DirectX support in order to read input from joysticks, you'd have to add some piece of Arduino-specific software to communicate with the Arduino board.

3- we just bought a virtual reality glasses that we want to use with our simulator.
¿can we use it within our cafu project in exchange of a mouse controller?
Well... why don't you try it out?
As above, if Cafu (and in fact, the OS, Windows) thinks it's a normal mouse, and if it roughly behaves like one, it seems that it should work. :cheesy:


Let me try to summarize all this:
  • If external devices such as Arduino or VR-glasses act as if they were keyboards or mice, and neither the Windows OS nor Cafu can tell the difference, the devices should work with Cafu out of the box.
  • If such devices act like joysticks, it is necessary to add the DirectX or SDL library support into Cafu first. With DirectX or SDL, Cafu can make use of joysticks like it can make use of keyboards and mice.
  • If devices communicate in some other, custom manner, it is up to the device manufacturer to provide you with code libraries that allow you to communicate with the device. You'd add such libraries to Cafu code like DirectX, SDL or any other "foreign" code library, and it's up to the details of these libraries how you can communicate with the connected device.
Hope this helps! :up:
Best regards,
Carsten
Sacramento
Posts:9
Joined:2013-08-30, 19:37

Re: Cafu for simulation question

Post by Sacramento » 2013-09-11, 02:32

thank you very much for all the help Carsten :D, ill try to figure it out how to make a connection with the engine.

im really interested of getting involved with cafu source code (its sounds challenging and fun) and also i always wanted to contribute with an open source software :D but im afraid that i couldn't understand anything :( or find what im looking for.

but again thank you for everything, and wish me luck to make this project run ;)
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Re: Cafu for simulation question

Post by Carsten » 2013-09-11, 16:17

Sacramento wrote:im really interested of getting involved with cafu source code (its sounds challenging and fun) and also i always wanted to contribute with an open source software :D but im afraid that i couldn't understand anything :( or find what im looking for.

but again thank you for everything, and wish me luck to make this project run ;)
You're welcome, and I wish you all the best and success with your plans!
If I can do anything else to help you now or in the future, just let me know.

A hint about the code: You should not spent too much effort on the code in Games/DeathMatch/Code. I'm currently working on the entity-component-system branch a lot, and when it's done, it will be a complete rewrite of the (DeathMatch) game code.
Everything else is pretty stable at the moment (assuming you use the “master” branch for normal work), so any time invested other code is well spent. :up:
Best regards,
Carsten
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests