mirror of https://github.com/fan-ziqi/rl_sar.git
feat: add gazebo service
This commit is contained in:
parent
e3873899ff
commit
dc10d01fed
|
@ -7,5 +7,5 @@ logs
|
||||||
*lite3*
|
*lite3*
|
||||||
*fldlar*
|
*fldlar*
|
||||||
.cache
|
.cache
|
||||||
.json
|
*.json
|
||||||
# *gr1t1*
|
# *gr1t1*
|
|
@ -7,6 +7,7 @@
|
||||||
#include <ros/ros.h>
|
#include <ros/ros.h>
|
||||||
#include <gazebo_msgs/ModelStates.h>
|
#include <gazebo_msgs/ModelStates.h>
|
||||||
#include <sensor_msgs/JointState.h>
|
#include <sensor_msgs/JointState.h>
|
||||||
|
#include "std_srvs/Empty.h"
|
||||||
#include <geometry_msgs/Twist.h>
|
#include <geometry_msgs/Twist.h>
|
||||||
#include "robot_msgs/MotorCommand.h"
|
#include "robot_msgs/MotorCommand.h"
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
@ -55,6 +56,7 @@ private:
|
||||||
ros::Subscriber joint_state_subscriber;
|
ros::Subscriber joint_state_subscriber;
|
||||||
ros::Subscriber cmd_vel_subscriber;
|
ros::Subscriber cmd_vel_subscriber;
|
||||||
std::map<std::string, ros::Publisher> torque_publishers;
|
std::map<std::string, ros::Publisher> torque_publishers;
|
||||||
|
ros::ServiceClient gazebo_reset_client;
|
||||||
void ModelStatesCallback(const gazebo_msgs::ModelStates::ConstPtr &msg);
|
void ModelStatesCallback(const gazebo_msgs::ModelStates::ConstPtr &msg);
|
||||||
void JointStatesCallback(const sensor_msgs::JointState::ConstPtr &msg);
|
void JointStatesCallback(const sensor_msgs::JointState::ConstPtr &msg);
|
||||||
void CmdvelCallback(const geometry_msgs::Twist::ConstPtr &msg);
|
void CmdvelCallback(const geometry_msgs::Twist::ConstPtr &msg);
|
||||||
|
|
|
@ -242,6 +242,7 @@ void RL::RunKeyboard()
|
||||||
case 'j': keyboard.y += 0.1; break;
|
case 'j': keyboard.y += 0.1; break;
|
||||||
case 'l': keyboard.y -= 0.1; break;
|
case 'l': keyboard.y -= 0.1; break;
|
||||||
case ' ': keyboard.x = 0; keyboard.y = 0; keyboard.yaw = 0; break;
|
case ' ': keyboard.x = 0; keyboard.y = 0; keyboard.yaw = 0; break;
|
||||||
|
case 'r': keyboard.keyboard_state = STATE_RESET_SIMULATION; break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ enum STATE {
|
||||||
STATE_RL_INIT,
|
STATE_RL_INIT,
|
||||||
STATE_RL_RUNNING,
|
STATE_RL_RUNNING,
|
||||||
STATE_POS_GETDOWN,
|
STATE_POS_GETDOWN,
|
||||||
|
STATE_RESET_SIMULATION,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct KeyBoard
|
struct KeyBoard
|
||||||
|
|
|
@ -57,6 +57,9 @@ RL_Sim::RL_Sim()
|
||||||
model_state_subscriber = nh.subscribe<gazebo_msgs::ModelStates>("/gazebo/model_states", 10, &RL_Sim::ModelStatesCallback, this);
|
model_state_subscriber = nh.subscribe<gazebo_msgs::ModelStates>("/gazebo/model_states", 10, &RL_Sim::ModelStatesCallback, this);
|
||||||
joint_state_subscriber = nh.subscribe<sensor_msgs::JointState>(ros_namespace + "joint_states", 10, &RL_Sim::JointStatesCallback, this);
|
joint_state_subscriber = nh.subscribe<sensor_msgs::JointState>(ros_namespace + "joint_states", 10, &RL_Sim::JointStatesCallback, this);
|
||||||
|
|
||||||
|
// service
|
||||||
|
gazebo_reset_client = nh.serviceClient<std_srvs::Empty>("/gazebo/reset_simulation");
|
||||||
|
|
||||||
// loop
|
// loop
|
||||||
loop_keyboard = std::make_shared<LoopFunc>("loop_keyboard", 0.05 , boost::bind(&RL_Sim::RunKeyboard, this));
|
loop_keyboard = std::make_shared<LoopFunc>("loop_keyboard", 0.05 , boost::bind(&RL_Sim::RunKeyboard, this));
|
||||||
loop_control = std::make_shared<LoopFunc>("loop_control" , 0.002, boost::bind(&RL_Sim::RobotControl, this));
|
loop_control = std::make_shared<LoopFunc>("loop_control" , 0.002, boost::bind(&RL_Sim::RobotControl, this));
|
||||||
|
@ -135,6 +138,13 @@ void RL_Sim::RobotControl()
|
||||||
|
|
||||||
motiontime++;
|
motiontime++;
|
||||||
|
|
||||||
|
if(keyboard.keyboard_state == STATE_RESET_SIMULATION)
|
||||||
|
{
|
||||||
|
keyboard.keyboard_state = STATE_WAITING;
|
||||||
|
std_srvs::Empty srv;
|
||||||
|
gazebo_reset_client.call(srv);
|
||||||
|
}
|
||||||
|
|
||||||
GetState(&robot_state);
|
GetState(&robot_state);
|
||||||
StateController(&robot_state, &robot_command);
|
StateController(&robot_state, &robot_command);
|
||||||
SetCommand(&robot_command);
|
SetCommand(&robot_command);
|
||||||
|
|
Loading…
Reference in New Issue