mysql connection using ROS
[
Front page
] [
New
|
List of pages
|
Search
|
Recent changes
|
Help
]
Start:
Up:[[Tutorial]]
----
The aim of this tutorial is to explain how to use mysql d...
In the example below, data are sent from SIGViewer to SIG...
#contents
*Packages creation [#ed1b8136]
Create 2 packages, sig_mysql and db_controller:
$ cd ~/catkin_ws/src
$ catkin_create_pkg sig_mysql
$ catkin_create_pkg db_controller
*Overview[#ed1b8137]
When the server is launched, 2 ros nodes are created, the...
Data are sent from the SIGViewer to the controller as mes...
&ref(overview.PNG,,80%); &ref(rosMysql.png,,80%);
*Server [#ed1b9133]
** SIGVerse controller [#ed1b9233]
This controller aims to receive data from SIGViewer and s...
sigMyql.cpp file:
#include "ControllerEvent.h"
#include "Controller.h"
#include "Logger.h"
#include <unistd.h>
#include <algorithm>
#include "ros/ros.h"
#include "std_msgs/String.h"
class MyController : public Controller {
public:
void onInit(InitEvent &evt);
double onAction(ActionEvent&);
void onRecvMsg(RecvMsgEvent &evt);
ros::Publisher chatter_pub;
private:
std::vector <std::string> m_trashes;
std_msgs::String msg;
};
void MyController::onInit(InitEvent &evt)
{
int argc =0;
char** argv = NULL;
ros::init(argc, argv, "SIG_Mysql");
ros::NodeHandle n;
chatter_pub = n.advertise<std_msgs::String>("database",...
}
double MyController::onAction(ActionEvent &evt)
{
return 1.0;
}
void MyController::onRecvMsg(RecvMsgEvent &evt){
msg.data = evt.getMsg();
if(msg.data != ""){
LOG_MSG(("message : %s", msg.data.c_str()));
}
chatter_pub.publish(msg);
msg.data ="";
}
extern "C" Controller * createController() {
return new MyController;
}
** Mysql controller[#ed1b9533]
This controller receives data from the SIGVerse controlle...
mysql_ros.cpp file:
// ROS includes
#include <ros/ros.h>
#include <signal.h>
#include <termios.h>
#include <stdio.h>
#include "std_msgs/String.h"
// Mysql includes
#include <my_global.h>
#include <mysql.h>
MYSQL *con = mysql_init(NULL);
int ID = 0;
std::ostringstream oss;
std::string querry;
void static finish_with_error(MYSQL *con)
{
fprintf(stderr, "%s\n", mysql_error(con));
mysql_close(con);
exit(1);
}
void chatterCallback(const std_msgs::String::ConstPtr& m...
{
ID = ID + 1;
oss << ID;
std::string IDStr = oss.str();
oss.str("");
querry = "INSERT INTO objects VALUES("+IDStr+",'"+msg->...
if (mysql_query(con, querry.c_str())) {
finish_with_error(con);
}
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "mysql_command");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("database", 1, chatte...
if (con == NULL)
{
fprintf(stderr, "%s\n", mysql_error(con));
exit(1);
}
if (mysql_real_connect(con, "localhost", "ericgt", "",
"sigverse", 0, NULL, 0) == NULL)
{
fprintf(stderr, "%s\n", mysql_error(con));
mysql_close(con);
exit(1);
}
if (mysql_query(con, "DROP TABLE IF EXISTS objects")) {
finish_with_error(con);
}
if (mysql_query(con, "CREATE TABLE objects(Id INT, Name...
finish_with_error(con);
}
ros::spin();
return(0);
}
*Compiling [#ed1b8132]
Add SIGVerse include path to CMakeLists.txt file:
include_directories (PATH-TO-SIGVERSE-LIBRARIES/include/s...
Then go to the catkin_ws directory to compile the project:
$ cd ~/catking_make
$ catkin_make
*World file [#ed1b8133]
Click on the link to download the world file:
#ref(mysql_world.xml)
The world file should be placed in "~/catkin_ws/devel/lib...
*Running the server[#ed1b8122]
To run the server you have to follow the following steps:
- Go to catkin_ws and execute the follwing command :
$ source ./devel/setup.bash
- Run the ROS system:
$ roscore
- run the ros mysql node :
$ rosrun database mysql_ros
- Go to ~/catkin_ws/devel/lib/libsigMysql and run the sig...
$ cd ~/catkin_ws/devel/lib/libsigMysql
$ sigserver.sh -w ./mysql_world.xml
*Download the project [#ed1b9563]
To download the project from GIT repository, use the foll...
git@socio4.iir.nii.ac.jp:~/SigverseGitServer/unstable/use...
#counter
End:
Up:[[Tutorial]]
----
The aim of this tutorial is to explain how to use mysql d...
In the example below, data are sent from SIGViewer to SIG...
#contents
*Packages creation [#ed1b8136]
Create 2 packages, sig_mysql and db_controller:
$ cd ~/catkin_ws/src
$ catkin_create_pkg sig_mysql
$ catkin_create_pkg db_controller
*Overview[#ed1b8137]
When the server is launched, 2 ros nodes are created, the...
Data are sent from the SIGViewer to the controller as mes...
&ref(overview.PNG,,80%); &ref(rosMysql.png,,80%);
*Server [#ed1b9133]
** SIGVerse controller [#ed1b9233]
This controller aims to receive data from SIGViewer and s...
sigMyql.cpp file:
#include "ControllerEvent.h"
#include "Controller.h"
#include "Logger.h"
#include <unistd.h>
#include <algorithm>
#include "ros/ros.h"
#include "std_msgs/String.h"
class MyController : public Controller {
public:
void onInit(InitEvent &evt);
double onAction(ActionEvent&);
void onRecvMsg(RecvMsgEvent &evt);
ros::Publisher chatter_pub;
private:
std::vector <std::string> m_trashes;
std_msgs::String msg;
};
void MyController::onInit(InitEvent &evt)
{
int argc =0;
char** argv = NULL;
ros::init(argc, argv, "SIG_Mysql");
ros::NodeHandle n;
chatter_pub = n.advertise<std_msgs::String>("database",...
}
double MyController::onAction(ActionEvent &evt)
{
return 1.0;
}
void MyController::onRecvMsg(RecvMsgEvent &evt){
msg.data = evt.getMsg();
if(msg.data != ""){
LOG_MSG(("message : %s", msg.data.c_str()));
}
chatter_pub.publish(msg);
msg.data ="";
}
extern "C" Controller * createController() {
return new MyController;
}
** Mysql controller[#ed1b9533]
This controller receives data from the SIGVerse controlle...
mysql_ros.cpp file:
// ROS includes
#include <ros/ros.h>
#include <signal.h>
#include <termios.h>
#include <stdio.h>
#include "std_msgs/String.h"
// Mysql includes
#include <my_global.h>
#include <mysql.h>
MYSQL *con = mysql_init(NULL);
int ID = 0;
std::ostringstream oss;
std::string querry;
void static finish_with_error(MYSQL *con)
{
fprintf(stderr, "%s\n", mysql_error(con));
mysql_close(con);
exit(1);
}
void chatterCallback(const std_msgs::String::ConstPtr& m...
{
ID = ID + 1;
oss << ID;
std::string IDStr = oss.str();
oss.str("");
querry = "INSERT INTO objects VALUES("+IDStr+",'"+msg->...
if (mysql_query(con, querry.c_str())) {
finish_with_error(con);
}
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "mysql_command");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("database", 1, chatte...
if (con == NULL)
{
fprintf(stderr, "%s\n", mysql_error(con));
exit(1);
}
if (mysql_real_connect(con, "localhost", "ericgt", "",
"sigverse", 0, NULL, 0) == NULL)
{
fprintf(stderr, "%s\n", mysql_error(con));
mysql_close(con);
exit(1);
}
if (mysql_query(con, "DROP TABLE IF EXISTS objects")) {
finish_with_error(con);
}
if (mysql_query(con, "CREATE TABLE objects(Id INT, Name...
finish_with_error(con);
}
ros::spin();
return(0);
}
*Compiling [#ed1b8132]
Add SIGVerse include path to CMakeLists.txt file:
include_directories (PATH-TO-SIGVERSE-LIBRARIES/include/s...
Then go to the catkin_ws directory to compile the project:
$ cd ~/catking_make
$ catkin_make
*World file [#ed1b8133]
Click on the link to download the world file:
#ref(mysql_world.xml)
The world file should be placed in "~/catkin_ws/devel/lib...
*Running the server[#ed1b8122]
To run the server you have to follow the following steps:
- Go to catkin_ws and execute the follwing command :
$ source ./devel/setup.bash
- Run the ROS system:
$ roscore
- run the ros mysql node :
$ rosrun database mysql_ros
- Go to ~/catkin_ws/devel/lib/libsigMysql and run the sig...
$ cd ~/catkin_ws/devel/lib/libsigMysql
$ sigserver.sh -w ./mysql_world.xml
*Download the project [#ed1b9563]
To download the project from GIT repository, use the foll...
git@socio4.iir.nii.ac.jp:~/SigverseGitServer/unstable/use...
#counter
Page: