Skip to content

Commit

Permalink
updated the inspexel code for the newest imported code
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdmaennchen committed Dec 16, 2019
1 parent afecc22 commit 281b1b9
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 37 deletions.
20 changes: 10 additions & 10 deletions src/detect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,26 @@ auto readDetailedInfos(dynamixel::USB2Dynamixel& usb2dyn, std::vector<std::tuple
}

void runDetect() {
baudrates.get().emplace(g_baudrate);
auto timeout = std::chrono::microseconds{g_timeout};
baudrates->emplace(*g_baudrate);
auto timeout = std::chrono::microseconds{*g_timeout};
auto protocols = std::vector<dynamixel::Protocol>{dynamixel::Protocol::V1, dynamixel::Protocol::V2};
if (g_protocolVersion.isSpecified()) {
protocols = {dynamixel::Protocol{int(g_protocolVersion)}};
if (g_protocolVersion) {
protocols = {dynamixel::Protocol{*g_protocolVersion}};
}
for (auto protocolVersion : protocols) {
std::cout << "# trying protocol version " << int(protocolVersion) << "\n";
for (auto baudrate : baudrates.get()) {
for (auto baudrate : *baudrates) {
std::cout << "## trying baudrate: " << baudrate << "\n";
auto usb2dyn = dynamixel::USB2Dynamixel(baudrate, g_device.get(), protocolVersion);
auto usb2dyn = dynamixel::USB2Dynamixel(baudrate, *g_device, protocolVersion);

// generate range to check
std::vector<int> range(0xFD);
std::iota(begin(range), end(range), 0);
if (g_id.isSpecified()) {
range = {MotorID(g_id)};
} else if (ids.isSpecified()) {
if (g_id) {
range = {*g_id};
} else if (ids) {
range.clear();
for (auto x : ids.get()) {
for (auto x : *ids) {
range.push_back(x);
}
}
Expand Down
16 changes: 7 additions & 9 deletions src/fsCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,20 @@ std::vector<std::unique_ptr<simplyfuse::FuseFile>> registerMotor(MotorID motorID
}

void runFuse() {
auto timeout = std::chrono::microseconds{g_timeout};
auto usb2dyn = USB2Dynamixel(g_baudrate, g_device.get(), Protocol{g_protocolVersion.get()});
auto timeout = std::chrono::microseconds{*g_timeout};
auto usb2dyn = USB2Dynamixel(*g_baudrate, *g_device, *g_protocolVersion);

std::vector<int> range;
if (g_id.isSpecified()) {
range = {MotorID(g_id)};
} else if (ids.isSpecified()) {
for (auto x : ids.get()) {
range.push_back(x);
}
if (g_id) {
range = {MotorID(*g_id)};
} else if (ids) {
std::copy(begin(*ids), end(*ids), std::back_inserter(range));
} else {
range.resize(0xfe);
std::iota(begin(range), end(range), 0);
}

simplyfuse::FuseFS fuseFS{mountPoint.get()};
simplyfuse::FuseFS fuseFS{*mountPoint};
std::map<MotorID, std::vector<std::unique_ptr<simplyfuse::FuseFile>>> files;

auto detectAndHandleMotor = [&](MotorID motor) {
Expand Down
6 changes: 5 additions & 1 deletion src/globalOptions.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <sargparse/Parameter.h>
#include "usb2dynamixel/USB2Dynamixel.h"


auto listDeviceFiles(std::vector<std::string> const& _str) -> std::pair<bool, std::set<std::string>>;
Expand All @@ -12,4 +13,7 @@ inline auto g_device = sargp::Parameter<std::string>(getDefaultSerialPo
inline auto g_id = sargp::Parameter<int>(0, "id", "the target Id (values: 0x00 - 0xfd)");
inline auto g_baudrate = sargp::Parameter<int>(1000000, "baudrate", "baudrate to use (e.g.: 1m)", {}, &listTypicalBaudrates);
inline auto g_timeout = sargp::Parameter<int>(10000, "timeout", "timeout in us");
inline auto g_protocolVersion = sargp::Parameter<int>(1, "protocol_version", "the dynamixel protocol version (values: 1, 2)");
inline auto g_protocolVersion = sargp::Choice<dynamixel::Protocol>(dynamixel::Protocol::V1, "protocol_version", {
{"1", dynamixel::Protocol::V1},
{"2", dynamixel::Protocol::V2}
}, "the dynamixel protocol version (values: 1, 2)");
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ int main(int argc, char** argv)
// pass everything except the name of the application
sargp::parseArguments(argc-1, argv+1);

if (printHelp.isSpecified()) {
if (printHelp) {
std::cout << "inspexel version " << VERSION << " - " << DATE << "\n";
std::cout << sargp::generateHelpString(std::regex{".*" + printHelp.get().value_or("") + ".*"});
std::cout << sargp::generateHelpString(std::regex{".*" + printHelp->value_or("") + ".*"});
return 0;
}
sargp::callCommands();
Expand Down
4 changes: 2 additions & 2 deletions src/metaCmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ void printDetailInfoTable(meta::MotorInfo const& data) {


void runMeta() {
if (optMotorName.isSpecified()) {
auto name = optMotorName.get();
if (optMotorName) {
auto name = *optMotorName;
std::transform(begin(name), end(name), begin(name), ::toupper);
auto info = meta::getMotorInfo(name);
if (not info) {
Expand Down
6 changes: 3 additions & 3 deletions src/rebootCmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ void runReboot();
auto rebootCmd = sargp::Command{"reboot", "reboot device with specified id", runReboot};

void runReboot() {
if (not g_id.isSpecified()) {
if (not g_id) {
throw std::runtime_error("must specify a id");
}
auto usb2dyn = dynamixel::USB2Dynamixel(g_baudrate, g_device.get(), dynamixel::Protocol(g_protocolVersion.get()));
usb2dyn.reboot(g_id);
auto usb2dyn = dynamixel::USB2Dynamixel(*g_baudrate, *g_device, *g_protocolVersion);
usb2dyn.reboot(*g_id);
}

}
20 changes: 10 additions & 10 deletions src/setValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ auto angle = setAngleCmd.Parameter<int>(0, "angle", "the goal angle (raw r

void runSetAngle() {
bool error = false;
if (not g_id.isSpecified()) {
if (not g_id) {
std::cout << "need to specify the target id!" << std::endl;
error = true;
}
if (not angle.isSpecified()) {
if (not angle) {
std::cout << "target angle has to be specified!" << std::endl;
error = true;
}
if (error) {
exit(-1);
}

auto usb2dyn = dynamixel::USB2Dynamixel(g_baudrate, g_device.get(), dynamixel::Protocol(g_protocolVersion.get()));
auto usb2dyn = dynamixel::USB2Dynamixel(*g_baudrate, *g_device, *g_protocolVersion);
auto [timeoutFlag, motorID, errorCode, layout] = usb2dyn.read<dynamixel::mx_v1::Register::MODEL_NUMBER, 2>(dynamixel::MotorID(g_id), std::chrono::microseconds{g_timeout});
if (timeoutFlag) {
std::cout << "the specified motor is not present" << std::endl;
Expand Down Expand Up @@ -55,9 +55,9 @@ auto values = setRegisterCmd.Parameter<std::vector<uint8_t>>({}, "values
auto ids = setRegisterCmd.Parameter<std::vector<int>>({}, "ids", "use this if you want to set multiple devices at once");

void runSetRegister() {
if (not g_id.isSpecified() and not ids.isSpecified()) throw std::runtime_error("need to specify the target g_id!");
if (not reg.isSpecified()) throw std::runtime_error("target register has to be specified!");
if (not values.isSpecified()) throw std::runtime_error("values to be written to the register have to be specified!");
if (not g_id and not ids) throw std::runtime_error("need to specify the target g_id!");
if (not reg) throw std::runtime_error("target register has to be specified!");
if (not values) throw std::runtime_error("values to be written to the register have to be specified!");

auto f = [&](int id) {
std::cout << "set register " << reg << " of motor " << id << " to";
Expand All @@ -72,10 +72,10 @@ void runSetRegister() {
auto usb2dyn = dynamixel::USB2Dynamixel(g_baudrate, g_device.get(), dynamixel::Protocol(g_protocolVersion.get()));
usb2dyn.write(id, int(reg), txBuf);
};
if (g_id.isSpecified()) {
if (g_id) {
f(g_id);
}
if (ids.isSpecified()) {
if (ids) {
for (auto id : ids.get()) {
f(id);
}
Expand All @@ -89,8 +89,8 @@ auto count = getRegisterCmd.Parameter<int>(1, "count", "amount of regis
auto timeout = getRegisterCmd.Parameter<int>(10000, "timeout", "timeout in us");

void runGetValue() {
if (not g_id.isSpecified()) throw std::runtime_error("need to specify the target g_id!");
if (not read_reg.isSpecified()) throw std::runtime_error("target angle has to be specified!");
if (not g_id) throw std::runtime_error("need to specify the target g_id!");
if (not read_reg) throw std::runtime_error("target angle has to be specified!");

auto usb2dyn = dynamixel::USB2Dynamixel(g_baudrate, g_device.get(), dynamixel::Protocol(g_protocolVersion.get()));
auto [timeoutFlag, valid, errorCode, rxBuf] = usb2dyn.read(g_id, read_reg, count, std::chrono::microseconds{timeout});
Expand Down

0 comments on commit 281b1b9

Please sign in to comment.