Skip to content

Commit d3a39ff

Browse files
committed
Added gazebo_usv interface for use with the USV
1 parent 8be5efb commit d3a39ff

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

vehicle_descriptions/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ link_directories(${GAZEBO_LIBRARY_DIRS})
4040
list(APPEND CMAKE_CXX_FLAGS "${GAZEBO_CXX_FLAGS}")
4141

4242
add_executable(gazebo_interface lib/mobility/src/gazebo_interface.cpp)
43+
add_executable(gazebo_interface_usv lib/mobility/src/gazebo_interface_usv.cpp)
4344
target_link_libraries(gazebo_interface ${catkin_LIBRARIES})
45+
target_link_libraries(gazebo_interface_usv ${catkin_LIBRARIES})
4446

4547
## Declare a C++ library
4648
# add_library(${PROJECT_NAME}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
#include "ros/ros.h"
3+
#include "gazebo_msgs/ModelState.h"
4+
#include <geometry_msgs/Pose2D.h>
5+
#include <tf2/LinearMath/Quaternion.h>
6+
7+
class SetState{
8+
private:
9+
ros::NodeHandle nh;
10+
ros::Publisher pub_state = nh.advertise<gazebo_msgs::ModelState>("/gazebo/set_model_state", 1000);
11+
ros::Subscriber sub_state = nh.subscribe("/vectornav/ins_2d/NED_pose", 1000, &SetState::stateCallback, this);
12+
tf2::Quaternion q;
13+
gazebo_msgs::ModelState model_msg;
14+
15+
public:
16+
void stateCallback(const geometry_msgs::Pose2D::ConstPtr& msg);
17+
};
18+
19+
void SetState::stateCallback(const geometry_msgs::Pose2D::ConstPtr& msg){
20+
model_msg.model_name = "vtec_s3";
21+
22+
// NED to ENU
23+
q.setRPY(0,0,-msg->theta);
24+
25+
model_msg.pose.position.x = msg->x;
26+
model_msg.pose.position.y = -msg->y;
27+
model_msg.pose.position.z = 0;
28+
29+
model_msg.pose.orientation.x = q.x();
30+
model_msg.pose.orientation.y = q.y();
31+
model_msg.pose.orientation.z = q.z();
32+
model_msg.pose.orientation.w = q.w();
33+
34+
pub_state.publish(model_msg);
35+
}
36+
37+
int main(int argc, char **argv){
38+
ros::init(argc,argv, "gazebo_interface");
39+
SetState state;
40+
ros::Rate rate(100);
41+
42+
while (ros::ok){
43+
rate.sleep(); // wait 10 Hz
44+
ros::spinOnce(); // will call all the callbacks waiting to be called at that point in time
45+
}
46+
47+
return 0;
48+
}

0 commit comments

Comments
 (0)