Skip to content

Commit 301bbc9

Browse files
committed
Add: Add a bin to reset all joints
1 parent a66a14c commit 301bbc9

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/bin/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
cmake_minimum_required(VERSION 2.7)
1717

1818
sa_add_bin(servo_array INSTALL)
19-
2019
sa_add_bin(servo_map INSTALL)
20+
sa_add_bin(reset INSTALL)
2121

2222
sa_add_bin(bench)

src/bin/reset.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This file is part of servoarray.
2+
//
3+
// servoarray is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// servoarray is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License
14+
// along with servoarray. If not, see <http://www.gnu.org/licenses/>.
15+
16+
#include "servoarray/servoarray.h"
17+
18+
#include <args.hxx>
19+
20+
#include <iostream>
21+
#include <cstdint>
22+
23+
int main(int argc, char **argv) {
24+
args::ArgumentParser argparser("Reset all joints");
25+
args::HelpFlag help(argparser, "help", "Print this help", {'h', "help"});
26+
args::Positional<std::string> arg_driver(argparser, "driver", "Driver name");
27+
28+
try {
29+
argparser.ParseCLI(argc, argv);
30+
} catch (const args::Help&){
31+
std::cout << argparser;
32+
return 0;
33+
} catch (const args::ParseError& e){
34+
std::cerr << e.what() << std::endl;
35+
std::cerr << argparser;
36+
return -1;
37+
}
38+
39+
const std::string driver {arg_driver ? args::get(arg_driver) : ""};
40+
41+
auto sa = ServoArray::ServoArray(driver);
42+
43+
for (std::size_t i = 0; i < sa.size(); i++) {
44+
sa[i] = 0;
45+
}
46+
}

0 commit comments

Comments
 (0)