1#include <visp3/core/vpColVector.h>
2#include <visp3/core/vpConfig.h>
3#include <visp3/core/vpSerial.h>
4#include <visp3/core/vpTime.h>
6int main(
int argc,
char *argv[])
9#ifdef ENABLE_VISP_NAMESPACE
16 bool rpm_command =
false;
20 for (
int i = 1;
i < argc;
i++) {
21 if ((std::string(argv[i]) ==
"--t" || std::string(argv[i]) ==
"-t") && i + 1 < argc) {
22 time =
static_cast<double>(atof(argv[++i]));
24 else if ((std::string(argv[i]) ==
"--vx" || std::string(argv[i]) ==
"-vx") && i + 1 < argc) {
25 v_x =
static_cast<double>(atof(argv[++i]));
27 else if ((std::string(argv[i]) ==
"--wz" || std::string(argv[i]) ==
"-wz") && i + 1 < argc) {
28 w_z =
static_cast<double>(atof(argv[++i]));
30 else if ((std::string(argv[i]) ==
"--rpm-l" || std::string(argv[i]) ==
"-rpm-l") && i + 1 < argc) {
32 rpm_l =
static_cast<double>(atoi(argv[++i]));
34 else if ((std::string(argv[i]) ==
"--rpm-r" || std::string(argv[i]) ==
"-rpm-r") && i + 1 < argc) {
36 rpm_r =
static_cast<double>(atoi(argv[++i]));
38 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
39 std::cout <<
"Usage: \n"
41 <<
" [--vx <linear velocity in m/s>]"
42 <<
" [--wz <rotational velocity in deg/s>]"
43 <<
" [--rpm-l <motor left RPM>]"
44 <<
" [--rpm-r <motor right RPM>]"
45 <<
" [--t <duration of the command in second>]"
48 std::cout <<
"\nExample:\n" << argv[0] <<
" --vx 0.05 --wz 0 --t 4\n" << std::endl;
53 vpSerial serial(
"/dev/ttyAMA0", 115200);
58 std::cout <<
"Apply rpm_l=" << rpm_l <<
" rpm_r=" << rpm_r <<
" during " << time <<
" seconds" << std::endl;
59 ss <<
"MOTOR_RPM=" << rpm_l <<
"," << rpm_r <<
"\n";
65 std::cout <<
"Apply v_x=" << v_x <<
" m/s "
66 <<
" w_z=" << w_z <<
" deg/s during " << time <<
" seconds" << std::endl;
67 double radius = 0.0325;
69 double motor_left = -(
v[0] + L *
v[1]) / radius;
70 double motor_right = (
v[0] - L *
v[1]) / radius;
71 std::cout <<
"Motor left vel: " << motor_left <<
" motor right vel: " << motor_right <<
" (rad/s)" << std::endl;
72 double rpm_left = motor_left * 30. / M_PI;
73 double rpm_right = motor_right * 30. / M_PI;
75 ss <<
"MOTOR_RPM=" <<
static_cast<int>(rpm_left) <<
"," <<
static_cast<int>(rpm_right) <<
"\n";
77 std::cout <<
"Send: " << ss.str() << std::endl;
80 serial.write(ss.str());
85 serial.write(
"MOTOR_RPM=-100,100\n");
87 serial.write(
"MOTOR_RPM=-50,100\n");
89 serial.write(
"MOTOR_RPM=50,-50\n");
91 serial.write(
"LED_RING=0,0,10,0\n");
93 serial.write(
"LED_RING=0,0,0,10\n");
95 serial.write(
"LED_RING=0,0,0,0\n");
101 std::cout <<
"Serial test is only working on unix-like OS." << std::endl;
Implementation of column vector and the associated operations.
static double rad(double deg)
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeSecond()
VISP_EXPORT void sleepMs(double t)