mirs
Toggle main menu visibility
読み取り中…
検索中…
一致する文字列を見つけられません
encoder_reset.cpp
[詳解]
1
// Copyright 2026 mirs260x
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a copy
4
// of this software and associated documentation files (the "Software"), to deal
5
// in the Software without restriction, including without limitation the rights
6
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
// copies of the Software, and to permit persons to whom the Software is
8
// furnished to do so, subject to the following conditions:
9
//
10
// The above copyright notice and this permission notice shall be included in
11
// all copies or substantial portions of the Software.
12
//
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
// THE SOFTWARE.
20
21
25
#include <chrono>
26
#include <cstdlib>
27
#include <memory>
28
29
#include "rclcpp/rclcpp.hpp"
30
#include "mirs_msgs/srv/simple_command.hpp"
31
32
using namespace
std::chrono_literals;
33
34
int
main
(
int
argc,
char
**argv)
35
{
36
rclcpp::init(argc, argv);
37
38
auto
node = rclcpp::Node::make_shared(
"encoder_reset"
);
39
auto
client = node->create_client<mirs_msgs::srv::SimpleCommand>(
"reset_encoder"
);
40
auto
request = std::make_shared<mirs_msgs::srv::SimpleCommand::Request>();
41
42
while
(!client->wait_for_service(1s)) {
43
if
(!rclcpp::ok()) {
44
RCLCPP_ERROR(node->get_logger(),
"Interrupted while waiting for the service. Exiting."
);
45
return
1;
46
}
47
RCLCPP_INFO(node->get_logger(),
"service not available, waiting again..."
);
48
}
49
50
auto
result = client->async_send_request(request);
51
if
(rclcpp::spin_until_future_complete(node, result) ==
52
rclcpp::FutureReturnCode::SUCCESS)
53
{
54
const
bool
ok = result.get()->success;
55
RCLCPP_INFO(node->get_logger(),
"Success: %s"
, ok ?
"true"
:
"false"
);
56
rclcpp::shutdown();
57
return
ok ? 0 : 1;
58
}
else
{
59
RCLCPP_ERROR(node->get_logger(),
"Failed to call service"
);
60
rclcpp::shutdown();
61
return
1;
62
}
63
}
main
int main(int argc, char **argv)
定義
basic_command.cpp:34
src
encoder_reset.cpp
構築:
1.18.0