Robotics StackExchange | Archived questions

Capture key press with a Gazebo plugin

I'm new in Gazebo and I want to control a robot with the keyboard writing my own plugin.

I have found how to move the model, following this tutorial: http://gazebosim.org/tutorials?tut=plugins_model&cat=write_plugin

I think is using this code:

this->model->SetLinearVel(ignition::math::Vector3d(.3, 0, 0));

But I don't know how when a key has been pressed and released.

How can I get those events in a plugin?

Asked by VansFannel on 2018-04-25 04:19:55 UTC

Comments

Answers

Good morning , me too i search the thing but i found an example that control the joints by kyes from key board

1- First you will use this 2 plugins :

KeyboardGUIPlugin, KeysToJointsPlugin from :

https://bitbucket.org/osrf/gazebo/src/f4e51e8f64001beda70615ab8982a7d5a4e65b18/plugins/KeyboardGUIPlugin.cc?at=default&fileviewer=file-view-default

https://bitbucket.org/osrf/gazebo/src/f4e51e8f64001beda70615ab8982a7d5a4e65b18/plugins/KeyboardGUIPlugin.hh?at=default&fileviewer=file-view-default

https://bitbucket.org/osrf/gazebo/src/f4e51e8f64001beda70615ab8982a7d5a4e65b18/plugins/KeysToJointsPlugin.cc?at=default&fileviewer=file-view-default

https://bitbucket.org/osrf/gazebo/src/f4e51e8f64001beda70615ab8982a7d5a4e65b18/plugins/KeysToJointsPlugin.hh?at=default&fileviewer=file-view-default

2- The world file :

https://bitbucket.org/osrf/gazebo/src/f4e51e8f64001beda70615ab8982a7d5a4e65b18/worlds/simple_arm_teleop.world?at=default&fileviewer=file-view-default

3- The CMakeLists.txt as :

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

find_package (Qt5Core REQUIRED)
find_package (Qt5Widgets REQUIRED)
set (CMAKE_AUTOMOC ON)

find_package(gazebo REQUIRED)
include_directories(${GAZEBO_INCLUDE_DIRS})
link_directories(${GAZEBO_LIBRARY_DIRS})
list(APPEND CMAKE_CXX_FLAGS "${GAZEBO_CXX_FLAGS}")

add_library(KeyboardGUIPlugin MODULE KeyboardGUIPlugin.cc)
target_link_libraries(KeyboardGUIPlugin ${GAZEBO_LIBRARIES} Qt5::Core)

add_library(KeysToJointsPlugin MODULE KeysToJointsPlugin.cc)
target_link_libraries(KeysToJointsPlugin ${GAZEBO_LIBRARIES} Qt5::Core)

4- then run it :

mkdir build
cd build
cmake ../
make
export GAZEBO_PLUGIN_PATH=`pwd`:$GAZEBO_PLUGIN_PATH
gazebo -u --verbose ../simple_arm_teleop.world

test keys 6, y, h, u, j, i, k :)

Did you found anything helpfull ? tahnks

Asked by AlberSaber on 2018-11-20 04:13:52 UTC

Comments

Yes, I'm doing it using ROS because it is easier.

Asked by VansFannel on 2018-11-20 13:43:29 UTC