-
Notifications
You must be signed in to change notification settings - Fork 16
/
contacts_example.cc
87 lines (73 loc) · 2.36 KB
/
contacts_example.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*!
\file examples/contacts_example.cc
\brief Contact world plugin example
\author João Borrego : jsbruglie
*/
#include "contacts_example.hh"
int main(int _argc, char **_argv)
{
// Load gazebo as a client
gazebo::client::setup(_argc, _argv);
// Create the communication node
gazebo::transport::NodePtr node(new gazebo::transport::Node());
node->Init();
// Publish to the target plugin request topic
gazebo::transport::PublisherPtr pub =
node->Advertise<grasp::msgs::ContactRequest>(REQUEST_TOPIC);
// Wait for a subscriber to connect to this publisher
pub->WaitForConnection();
// Main loop
std::string line = "";
while (std::cout << PROMPT)
{
// Process command
getline(std::cin, line);
std::stringstream input_stream(line);
std::string command = input_stream.str();
// Check for collision between box and ground plane
if (command == "check")
{
std::string col1("ground_plane"), col2("box");
getContactBetween(pub, col1, col2);
}
else if (command == "change")
{
std::string model("box"), link("link"),
collision("box_collision");
changeSurface(pub, model, link, collision);
}
}
// Shut down
gazebo::client::shutdown();
return 0;
}
/////////////////////////////////////////////////
void getContactBetween(gazebo::transport::PublisherPtr pub,
const std::string & collision1,
const std::string & collision2)
{
ContactRequest msg;
CollisionRequest *pair = msg.add_collision();
pair->set_collision1(collision1);
pair->set_collision2(collision2);
pub->Publish(msg);
}
/////////////////////////////////////////////////
void changeSurface(gazebo::transport::PublisherPtr pub,
const std::string & model,
const std::string & link,
const std::string & collision)
{
ContactRequest msg;
SurfaceRequest *req = msg.add_surface();
req->set_model(model);
req->set_link(link);
req->set_collision(collision);
gazebo::msgs::Surface *surface = new gazebo::msgs::Surface();
gazebo::msgs::Friction *friction = new gazebo::msgs::Friction();
friction->set_mu(10000.0);
friction->set_mu2(10000.0);
surface->set_allocated_friction(friction);
req->set_allocated_surface(surface);
pub->Publish(msg);
}