|
13 | 13 |
|
14 | 14 | #include <viam/sdk/common/instance.hpp> |
15 | 15 | #include <viam/sdk/components/motor.hpp> |
| 16 | +#include <viam/sdk/log/logging.hpp> |
16 | 17 | #include <viam/sdk/robot/client.hpp> |
17 | 18 | #include <viam/sdk/rpc/dial.hpp> |
18 | 19 |
|
@@ -48,54 +49,61 @@ int main() { |
48 | 49 | // Connect to robot. |
49 | 50 | std::shared_ptr<RobotClient> robot = RobotClient::at_address(address, options); |
50 | 51 | // Print resources. |
51 | | - std::cout << "Resources" << std::endl; |
| 52 | + VIAM_SDK_LOG(info) << "Resources:"; |
52 | 53 | std::vector<Name> resource_names = robot->resource_names(); |
53 | 54 | for (const Name& resource : resource_names) { |
54 | | - std::cout << "\t" << resource << "\n"; |
| 55 | + VIAM_SDK_LOG(info) << resource; |
55 | 56 | } |
56 | 57 |
|
57 | 58 | // Exercise Gizmo methods. |
58 | 59 | auto gc = robot->resource_by_name<Gizmo>("gizmo1"); |
59 | 60 | if (!gc) { |
60 | | - std::cerr << "could not get 'gizmo1' resource from robot" << std::endl; |
| 61 | + VIAM_SDK_LOG(error) << "could not get 'gizmo1' resource from robot" << std::endl; |
61 | 62 | return EXIT_FAILURE; |
62 | 63 | } |
| 64 | + |
63 | 65 | bool do_one_ret = gc->do_one("arg1"); |
64 | | - std::cout << "gizmo1 do_one returned: " << do_one_ret << std::endl; |
| 66 | + VIAM_SDK_LOG(info) << "gizmo1 do_one returned: " << do_one_ret; |
| 67 | + |
65 | 68 | bool do_one_client_stream_ret = gc->do_one_client_stream({"arg1", "arg1", "arg1"}); |
66 | | - std::cout << "gizmo1 do_one_client_stream returned: " << do_one_client_stream_ret << std::endl; |
| 69 | + VIAM_SDK_LOG(info) << "gizmo1 do_one_client_stream returned: " << do_one_client_stream_ret; |
| 70 | + |
67 | 71 | std::string do_two_ret = gc->do_two(false); |
68 | | - std::cout << "gizmo1 do_two returned: " << do_two_ret << std::endl; |
| 72 | + VIAM_SDK_LOG(info) << "gizmo1 do_two returned: " << do_two_ret; |
| 73 | + |
69 | 74 | std::vector<bool> do_one_server_stream_ret = gc->do_one_server_stream("arg1"); |
70 | | - std::cout << "gizmo1 do_one_server_stream returned: " << std::endl; |
| 75 | + VIAM_SDK_LOG(info) << "gizmo1 do_one_server_stream returned: "; |
71 | 76 | for (bool ret : do_one_server_stream_ret) { |
72 | | - std::cout << '\t' << ret << std::endl; |
| 77 | + VIAM_SDK_LOG(info) << ret; |
73 | 78 | } |
| 79 | + |
74 | 80 | std::vector<bool> do_one_bidi_stream_ret = gc->do_one_bidi_stream({"arg1", "arg2", "arg3"}); |
75 | | - std::cout << "gizmo1 do_one_bidi_stream returned: " << std::endl; |
| 81 | + VIAM_SDK_LOG(info) << "gizmo1 do_one_bidi_stream returned: "; |
76 | 82 | for (bool ret : do_one_bidi_stream_ret) { |
77 | | - std::cout << '\t' << ret << std::endl; |
| 83 | + VIAM_SDK_LOG(info) << ret; |
78 | 84 | } |
79 | 85 |
|
80 | 86 | // Exercise Summation methods. |
81 | 87 | auto sc = robot->resource_by_name<Summation>("mysum1"); |
82 | 88 | if (!sc) { |
83 | | - std::cerr << "could not get 'mysum1' resource from robot" << std::endl; |
| 89 | + VIAM_SDK_LOG(error) << "could not get 'mysum1' resource from robot"; |
84 | 90 | return EXIT_FAILURE; |
85 | 91 | } |
| 92 | + |
86 | 93 | double sum = sc->sum({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); |
87 | | - std::cout << "mysum1 sum of numbers [0, 10) is: " << sum << std::endl; |
| 94 | + VIAM_SDK_LOG(info) << "mysum1 sum of numbers [0, 10) is: " << sum; |
88 | 95 |
|
89 | 96 | // Exercise a Base method. |
90 | 97 | auto mc = robot->resource_by_name<Motor>("motor1"); |
91 | 98 | if (!mc) { |
92 | | - std::cerr << "could not get 'motor1' resource from robot" << std::endl; |
| 99 | + VIAM_SDK_LOG(error) << "could not get 'motor1' resource from robot"; |
93 | 100 | return EXIT_FAILURE; |
94 | 101 | } |
| 102 | + |
95 | 103 | if (mc->is_moving()) { |
96 | | - std::cout << "motor1 is moving" << std::endl; |
| 104 | + VIAM_SDK_LOG(info) << "motor1 is moving"; |
97 | 105 | } else { |
98 | | - std::cout << "motor1 is not moving" << std::endl; |
| 106 | + VIAM_SDK_LOG(info) << "motor1 is not moving"; |
99 | 107 | } |
100 | 108 |
|
101 | 109 | return EXIT_SUCCESS; |
|
0 commit comments