Skip to content

Commit

Permalink
[examples] allow to override default parameter via CMD line parameter. (
Browse files Browse the repository at this point in the history
  • Loading branch information
aentinger authored Jul 12, 2023
1 parent e6b2b45 commit 8666554
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 14 deletions.
22 changes: 20 additions & 2 deletions examples/example-01-ping/example-01-ping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <cstdlib>

#include <sstream>
#include <iostream>

#include <dynamixel++/dynamixel++.h>
Expand All @@ -27,9 +28,26 @@ using namespace dynamixelplusplus;

int main(int argc, char **argv) try
{
Dynamixel dynamixel_ctrl("/dev/serial/by-id/usb-FTDI_USB__-__Serial_Converter_FT4NNZ55-if00-port0",
size_t const DEFAULT_BAUD_RATE = 115200;
std::string const DEFAULT_DEVICE_NAME = "/dev/serial/by-id/usb-FTDI_USB__-__Serial_Converter_FT4NNZ55-if00-port0";

size_t baud_rate{DEFAULT_BAUD_RATE};
std::string device_name{DEFAULT_DEVICE_NAME};

if (argc > 1) {
device_name = std::string(argv[1]);
}
if (argc > 2) {
std::stringstream baud_rate_ss;
baud_rate_ss << argv[2];
baud_rate_ss >> baud_rate;
}

std::cout << "configured for \"" << device_name << "\" with a baud rate of \"" << baud_rate << "\"." << std::endl;

Dynamixel dynamixel_ctrl(device_name,
Dynamixel::Protocol::V2_0,
115200);
baud_rate);

auto const id_vect = dynamixel_ctrl.broadcastPing();

Expand Down
22 changes: 20 additions & 2 deletions examples/example-02-read/example-02-read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <cstdlib>

#include <sstream>
#include <iostream>

#include <dynamixel++/dynamixel++.h>
Expand All @@ -34,9 +35,26 @@ static uint16_t const MX28_ControlTable_HardwareErrorStatus = 70;

int main(int argc, char **argv) try
{
Dynamixel dynamixel_ctrl("/dev/serial/by-id/usb-FTDI_USB__-__Serial_Converter_FT4NNZ55-if00-port0",
size_t const DEFAULT_BAUD_RATE = 115200;
std::string const DEFAULT_DEVICE_NAME = "/dev/serial/by-id/usb-FTDI_USB__-__Serial_Converter_FT4NNZ55-if00-port0";

size_t baud_rate{DEFAULT_BAUD_RATE};
std::string device_name{DEFAULT_DEVICE_NAME};

if (argc > 1) {
device_name = std::string(argv[1]);
}
if (argc > 2) {
std::stringstream baud_rate_ss;
baud_rate_ss << argv[2];
baud_rate_ss >> baud_rate;
}

std::cout << "configured for \"" << device_name << "\" with a baud rate of \"" << baud_rate << "\"." << std::endl;

Dynamixel dynamixel_ctrl(device_name,
Dynamixel::Protocol::V2_0,
115200);
baud_rate);

/* Send a broadcast ping to determine which
* servos are available (more convenient for
Expand Down
22 changes: 20 additions & 2 deletions examples/example-03-bulk-read/example-03-bulk-read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <cstdlib>

#include <sstream>
#include <iostream>

#include <dynamixel++/dynamixel++.h>
Expand All @@ -34,9 +35,26 @@ static uint16_t const MX28_ControlTable_PresentPosition = 132;

int main(int argc, char **argv) try
{
Dynamixel dynamixel_ctrl("/dev/serial/by-id/usb-FTDI_USB__-__Serial_Converter_FT4NNZ55-if00-port0",
size_t const DEFAULT_BAUD_RATE = 115200;
std::string const DEFAULT_DEVICE_NAME = "/dev/serial/by-id/usb-FTDI_USB__-__Serial_Converter_FT4NNZ55-if00-port0";

size_t baud_rate{DEFAULT_BAUD_RATE};
std::string device_name{DEFAULT_DEVICE_NAME};

if (argc > 1) {
device_name = std::string(argv[1]);
}
if (argc > 2) {
std::stringstream baud_rate_ss;
baud_rate_ss << argv[2];
baud_rate_ss >> baud_rate;
}

std::cout << "configured for \"" << device_name << "\" with a baud rate of \"" << baud_rate << "\"." << std::endl;

Dynamixel dynamixel_ctrl(device_name,
Dynamixel::Protocol::V2_0,
115200);
baud_rate);

/* Send a broadcast ping to determine which
* servos are available (more convenient for
Expand Down
22 changes: 20 additions & 2 deletions examples/example-04-sync-read/example-04-sync-read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <cstdlib>

#include <sstream>
#include <iostream>

#include <dynamixel++/dynamixel++.h>
Expand All @@ -34,9 +35,26 @@ static uint16_t const MX28_ControlTable_PresentPosition = 132;

int main(int argc, char **argv) try
{
Dynamixel dynamixel_ctrl("/dev/serial/by-id/usb-FTDI_USB__-__Serial_Converter_FT4NNZ55-if00-port0",
size_t const DEFAULT_BAUD_RATE = 115200;
std::string const DEFAULT_DEVICE_NAME = "/dev/serial/by-id/usb-FTDI_USB__-__Serial_Converter_FT4NNZ55-if00-port0";

size_t baud_rate{DEFAULT_BAUD_RATE};
std::string device_name{DEFAULT_DEVICE_NAME};

if (argc > 1) {
device_name = std::string(argv[1]);
}
if (argc > 2) {
std::stringstream baud_rate_ss;
baud_rate_ss << argv[2];
baud_rate_ss >> baud_rate;
}

std::cout << "configured for \"" << device_name << "\" with a baud rate of \"" << baud_rate << "\"." << std::endl;

Dynamixel dynamixel_ctrl(device_name,
Dynamixel::Protocol::V2_0,
115200);
baud_rate);

/* Send a broadcast ping to determine which
* servos are available (more convenient for
Expand Down
22 changes: 20 additions & 2 deletions examples/example-05-write/example-05-write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <cstdlib>

#include <thread>
#include <sstream>
#include <iostream>

#include <dynamixel++/dynamixel++.h>
Expand Down Expand Up @@ -42,9 +43,26 @@ void turnLedOff(Dynamixel & dynamixel_ctrl, Dynamixel::Id const id);

int main(int argc, char **argv) try
{
Dynamixel dynamixel_ctrl("/dev/serial/by-id/usb-FTDI_USB__-__Serial_Converter_FT4NNZ55-if00-port0",
size_t const DEFAULT_BAUD_RATE = 115200;
std::string const DEFAULT_DEVICE_NAME = "/dev/serial/by-id/usb-FTDI_USB__-__Serial_Converter_FT4NNZ55-if00-port0";

size_t baud_rate{DEFAULT_BAUD_RATE};
std::string device_name{DEFAULT_DEVICE_NAME};

if (argc > 1) {
device_name = std::string(argv[1]);
}
if (argc > 2) {
std::stringstream baud_rate_ss;
baud_rate_ss << argv[2];
baud_rate_ss >> baud_rate;
}

std::cout << "configured for \"" << device_name << "\" with a baud rate of \"" << baud_rate << "\"." << std::endl;

Dynamixel dynamixel_ctrl(device_name,
Dynamixel::Protocol::V2_0,
115200);
baud_rate);

/* Send a broadcast ping to determine which
* servos are available (more convenient for
Expand Down
22 changes: 20 additions & 2 deletions examples/example-06-bulk-write/example-06-bulk-write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <cstdlib>

#include <thread>
#include <sstream>
#include <iostream>

#include <dynamixel++/dynamixel++.h>
Expand Down Expand Up @@ -42,9 +43,26 @@ void turnLedOff(Dynamixel & dynamixel_ctrl, Dynamixel::IdVect const & id_vect);

int main(int argc, char **argv) try
{
Dynamixel dynamixel_ctrl("/dev/serial/by-id/usb-FTDI_USB__-__Serial_Converter_FT4NNZ55-if00-port0",
size_t const DEFAULT_BAUD_RATE = 115200;
std::string const DEFAULT_DEVICE_NAME = "/dev/serial/by-id/usb-FTDI_USB__-__Serial_Converter_FT4NNZ55-if00-port0";

size_t baud_rate{DEFAULT_BAUD_RATE};
std::string device_name{DEFAULT_DEVICE_NAME};

if (argc > 1) {
device_name = std::string(argv[1]);
}
if (argc > 2) {
std::stringstream baud_rate_ss;
baud_rate_ss << argv[2];
baud_rate_ss >> baud_rate;
}

std::cout << "configured for \"" << device_name << "\" with a baud rate of \"" << baud_rate << "\"." << std::endl;

Dynamixel dynamixel_ctrl(device_name,
Dynamixel::Protocol::V2_0,
115200);
baud_rate);

/* Send a broadcast ping to determine which
* servos are available (more convenient for
Expand Down
22 changes: 20 additions & 2 deletions examples/example-07-sync-write/example-07-sync-write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <cstdlib>

#include <thread>
#include <sstream>
#include <iostream>

#include <dynamixel++/dynamixel++.h>
Expand Down Expand Up @@ -42,9 +43,26 @@ void turnLedOff(Dynamixel & dynamixel_ctrl, Dynamixel::IdVect const & id_vect);

int main(int argc, char **argv) try
{
Dynamixel dynamixel_ctrl("/dev/serial/by-id/usb-FTDI_USB__-__Serial_Converter_FT4NNZ55-if00-port0",
size_t const DEFAULT_BAUD_RATE = 115200;
std::string const DEFAULT_DEVICE_NAME = "/dev/serial/by-id/usb-FTDI_USB__-__Serial_Converter_FT4NNZ55-if00-port0";

size_t baud_rate{DEFAULT_BAUD_RATE};
std::string device_name{DEFAULT_DEVICE_NAME};

if (argc > 1) {
device_name = std::string(argv[1]);
}
if (argc > 2) {
std::stringstream baud_rate_ss;
baud_rate_ss << argv[2];
baud_rate_ss >> baud_rate;
}

std::cout << "configured for \"" << device_name << "\" with a baud rate of \"" << baud_rate << "\"." << std::endl;

Dynamixel dynamixel_ctrl(device_name,
Dynamixel::Protocol::V2_0,
115200);
baud_rate);

/* Send a broadcast ping to determine which
* servos are available (more convenient for
Expand Down

0 comments on commit 8666554

Please sign in to comment.