1 #include <visp3/core/vpColVector.h> 2 #include <visp3/core/vpSerial.h> 3 #include <visp3/core/vpTime.h> 5 int main(
int argc,
char *argv[])
11 bool rpm_command =
false;
15 for (
int i = 1; i < argc; i++) {
16 if ((std::string(argv[i]) ==
"--t" || std::string(argv[i]) ==
"-t") && i+1 < argc) {
17 time = (double)atof(argv[i+1]);
18 }
else if ((std::string(argv[i]) ==
"--vx" || std::string(argv[i]) ==
"-vx") && i+1 < argc) {
19 v_x = (double)atof(argv[i+1]);
20 }
else if ((std::string(argv[i]) ==
"--wz" || std::string(argv[i]) ==
"-wz") && i+1 < argc) {
21 w_z = (double)atof(argv[i+1]);
22 }
else if ((std::string(argv[i]) ==
"--rpm_l" || std::string(argv[i]) ==
"-rpm_l") && i+1 < argc) {
24 rpm_l = (double)atoi(argv[i+1]);
25 }
else if ((std::string(argv[i]) ==
"--rpm_r" || std::string(argv[i]) ==
"-rpm_r") && i+1 < argc) {
27 rpm_r = (double)atoi(argv[i+1]);
28 }
else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
29 std::cout <<
"Usage: \n" << argv[0] <<
" --vx <linear velocity in m/s> --wz <rotational velocity in deg/s> --rpm_l <motor left RPM> --rpm_r <motor right RPM> --t <duration of the command in second> --help" << std::endl;
30 std::cout <<
"\nExample:\n" << argv[0] <<
" --vx 0.05 --wz 0 --t 4\n" << std::endl;
35 vpSerial serial(
"/dev/ttyAMA0", 115200);
40 std::cout <<
"Apply rpm_l=" << rpm_l <<
" rpm_r=" << rpm_r <<
" during " << time <<
" seconds" << std::endl;
41 ss <<
"MOTOR_RPM=" << rpm_l <<
"," << rpm_r <<
"\n";
47 std::cout <<
"Apply v_x=" << v_x <<
" m/s "<<
" w_z=" << w_z <<
" deg/s during " << time <<
" seconds" << std::endl;
48 double radius = 0.0325;
50 double motor_left = -(v[0] + L * v[1]) / radius;
51 double motor_right = (v[0] - L * v[1]) / radius;
52 std::cout <<
"Motor left vel: " << motor_left <<
" motor right vel: " << motor_right <<
" (rad/s)" << std::endl;
53 double rpm_left = motor_left * 30. / M_PI;
54 double rpm_right = motor_right * 30. / M_PI;
56 ss <<
"MOTOR_RPM=" << (int)rpm_left <<
"," << (
int)rpm_right << "\n";
58 std::cout << "Send: " << ss.str() <<
std::endl;
59 double t0 =
vpTime::measureTimeSecond();
60 while(
vpTime::measureTimeSecond() - t0 < time) {
61 serial.write(ss.str());
66 serial.write(
"MOTOR_RPM=-100,100\n");
68 serial.write(
"MOTOR_RPM=-50,100\n");
70 serial.write(
"MOTOR_RPM=50,-50\n");
72 serial.write(
"LED_RING=0,0,10,0\n");
74 serial.write(
"LED_RING=0,0,0,10\n");
76 serial.write(
"LED_RING=0,0,0,0\n");
82 std::cout <<
"Serial test is only working on unix-like OS." << std::endl;
VISP_EXPORT int wait(double t0, double t)
Time management and measurement.
VISP_EXPORT void sleepMs(double t)
static double rad(double deg)
Implementation of column vector and the associated operations.