Robotran C Documentation
Functions
user_realtime_events.c File Reference

Handles the events coming from the keyboard or from other sources via the SDL framework. More...

#include "mbs_data.h"
#include "mbs_project_fct_ptr.h"
#include "realtime.h"
#include "user_realtime.h"

Functions

void user_keyboard (MbsData *mbs_data, Simu_realtime *realtime, int cur_t_usec, const Uint8 *keystates)
 handle inputs comming from the keyboard More...
 
void user_joystick_axes (MbsData *mbs_data, Simu_realtime *realtime, int nb_joysticks)
 handle inputs comming from joysticks axes More...
 
void user_joystick_buttons (MbsData *mbs_data, int buttonID)
 handle inputs comming from joysticks buttons More...
 

Detailed Description

Handles the events coming from the keyboard or from other sources via the SDL framework.

Author
Nicolas Van der Noot

In order to use C++ features, you just need to change the extension of this file (.c) to .cc (or .cpp).

Function Documentation

◆ user_joystick_axes()

void user_joystick_axes ( MbsData mbs_data,
Simu_realtime realtime,
int  nb_joysticks 
)

handle inputs comming from joysticks axes

Parameters
[in,out]mbs_dataRobotran main structure
[in]realtimereal-time structure
[in]nb_joysticksnumber of joysticks detected

Use get_Joystick_axis(int joystickID, int axisID, Simu_realtime *realtime) to return the value associated with the joystick number joystickID

joystickID: ID of the joystick (starting at 0) axisID: ID of the axis (starting at 0)

get_Joystick_axis returns a value in [-1 ; 1] or -10 if this joystickID is not available

plugged joysticks are automatically detected at launch (see nb_joysticks)

example: joystick_val = get_Joystick_axis(0, 0, realtime); mbs_data->user_IO->my_variable = joystick_val * scaling_factor;

◆ user_joystick_buttons()

void user_joystick_buttons ( MbsData mbs_data,
int  buttonID 
)

handle inputs comming from joysticks buttons

Parameters
[in,out]mbs_dataRobotran main structure
[in]buttonIDID of the joystick button

buttonID takes a value (usually starting at 0) when a joystick button is pressed

Use printf to detect which 'buttonID' is used for the different buttons.

example: if (buttonID == 2) { mbs_data->user_IO->my_command++; }

◆ user_keyboard()

void user_keyboard ( MbsData mbs_data,
Simu_realtime realtime,
int  cur_t_usec,
const Uint8 keystates 
)

handle inputs comming from the keyboard

Parameters
[in,out]mbs_dataRobotran main structure
[in]realtimereal-time structure
[in]cur_t_useccurent time [us]
[in]keystatesstate of the keys (from the keyboard)

Use keystates'key code' to detect when the corresponding key is pressed and add your own functions according to the key pressed.

Call 'wait_key(realtime, cur_t_usec, time);' in the statement where you replace 'time' by a time in seconds if you want to wait before detecting a new user command. Pay attention, when you call 'wait_key', the program is automatically kept awake for a few seconds. Consequently, the process can not be realeased after a few seconds during a break in case 'wait_key' is always called.

example: if (keystates[SDL_SCANCODE_UP]) { mbs_data->user_IO->my_command++; wait_key(realtime, cur_t_usec, 0.1); } else if (keystates[SDL_SCANCODE_DOWN]) { mbs_data->user_IO->my_command–; wait_key(realtime, cur_t_usec, 0.1); }