1 #include <visp3/core/vpColVector.h>
2 #include <visp3/core/vpConfig.h>
3 #include <visp3/core/vpSerial.h>
4 #include <visp3/core/vpTime.h>
6 int 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 = (double)atof(argv[i + 1]);
24 else if ((std::string(argv[i]) ==
"--vx" || std::string(argv[i]) ==
"-vx") && i + 1 < argc) {
25 v_x = (double)atof(argv[i + 1]);
27 else if ((std::string(argv[i]) ==
"--wz" || std::string(argv[i]) ==
"-wz") && i + 1 < argc) {
28 w_z = (double)atof(argv[i + 1]);
30 else if ((std::string(argv[i]) ==
"--rpm_l" || std::string(argv[i]) ==
"-rpm_l") && i + 1 < argc) {
32 rpm_l = (double)atoi(argv[i + 1]);
34 else if ((std::string(argv[i]) ==
"--rpm_r" || std::string(argv[i]) ==
"-rpm_r") && i + 1 < argc) {
36 rpm_r = (double)atoi(argv[i + 1]);
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> --wz <rotational velocity in deg/s> --rpm_l <motor left RPM> "
42 "--rpm_r <motor right RPM> --t <duration of the command in second> --help"
44 std::cout <<
"\nExample:\n" << argv[0] <<
" --vx 0.05 --wz 0 --t 4\n" << std::endl;
49 vpSerial serial(
"/dev/ttyAMA0", 115200);
54 std::cout <<
"Apply rpm_l=" << rpm_l <<
" rpm_r=" << rpm_r <<
" during " << time <<
" seconds" << std::endl;
55 ss <<
"MOTOR_RPM=" << rpm_l <<
"," << rpm_r <<
"\n";
61 std::cout <<
"Apply v_x=" << v_x <<
" m/s "
62 <<
" w_z=" << w_z <<
" deg/s during " << time <<
" seconds" << std::endl;
63 double radius = 0.0325;
65 double motor_left = -(v[0] + L * v[1]) / radius;
66 double motor_right = (v[0] - L * v[1]) / radius;
67 std::cout <<
"Motor left vel: " << motor_left <<
" motor right vel: " << motor_right <<
" (rad/s)" << std::endl;
68 double rpm_left = motor_left * 30. / M_PI;
69 double rpm_right = motor_right * 30. / M_PI;
71 ss <<
"MOTOR_RPM=" << (int)rpm_left <<
"," << (
int)rpm_right <<
"\n";
73 std::cout <<
"Send: " << ss.str() << std::endl;
76 serial.write(ss.str());
81 serial.write(
"MOTOR_RPM=-100,100\n");
83 serial.write(
"MOTOR_RPM=-50,100\n");
85 serial.write(
"MOTOR_RPM=50,-50\n");
87 serial.write(
"LED_RING=0,0,10,0\n");
89 serial.write(
"LED_RING=0,0,0,10\n");
91 serial.write(
"LED_RING=0,0,0,0\n");
97 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)