Tutorial?
The aim of this tutorial is to introduce how to control a SIGVerse robot using Joystick. The example below allows to control a robot in 4 directions: moving forward, backward, turning left and right.
Download and install Microsoft directx sdk
The controller receives data from the joystick service as messages using the joystick, sets the corresponding velocity then sends the command to the robot.
joystick.cpp:
#include "Controller.h" #include "Logger.h" #include <unistd.h> #include "ControllerEvent.h" #include <sstream> class voiceRecognition : public Controller { public: void onInit(InitEvent &evt); double onAction(ActionEvent &evt); void onRecvMsg(RecvMsgEvent &evt); public: RobotObj *my; double velocity; int i; double direction1; double direction2; int j; double Weel_one; double Weel_two; }; void voiceRecognition::onInit(InitEvent &evt) { Weel_one = 0.0; Weel_two = 0.0; my = this->getRobotObj(this->myname()); my->setWheel(10.0, 10.0); } double voiceRecognition::onAction(ActionEvent &evt) { my->setWheelVelocity(Weel_one,Weel_two); return 0.01; } void voiceRecognition::onRecvMsg(RecvMsgEvent &evt) { std::string sender = evt.getSender(); std::string msg = evt.getMsg(); LOG_MSG(("message : %s", msg.c_str())); if(strcmp("moveforward",msg.c_str())==0) { Weel_one = 3.0; Weel_two = 3.0; } else if(strcmp("movebackward",msg.c_str())==0) { Weel_one = -3.0; Weel_two = -3.0; } else if(strcmp("turnleft",msg.c_str())==0) { Weel_one = -0.78; Weel_two = 0.78; } else if(strcmp("turnright",msg.c_str())==0) { Weel_one = 0.78; Weel_two = -0.78; } } extern "C" Controller * createController () { return new voiceRecognition; }
The service receives data from the joystick, for each button of the joystick corresponds an action, the allowed actions are: move forward, move backward, turn left and turn right, when a button is pressed, the appropriate message is sent to the controller to move the robot.
Joystick_Service.cpp
To download the plugin:
joystickWorld.xml
To download the project from GIT repository, use the following link:
git@socio4.iir.nii.ac.jp:~/SigverseGitServer/unstable/usersContribution/tafifet/ros_joystick.git