segwayrmp_example.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include <algorithm>
4 
5 #include "segwayrmp/segwayrmp.h"
6 
8  std::cout << ss->str() << std::endl << std::endl;
9 }
10 
11 int run_segway(segwayrmp::InterfaceType interface_type, std::string configuration, int config_type = 0) {
12  std::cout << "!!!!!!!!!!!!WARNING!!!!!!!!!!!!" << std::endl;
13  std::cout << "This example moves the segway!!" << std::endl;
14  std::cout << "(If you continue, ctrl-c quits)" << std::endl;
15  std::cout << "Do you want to continue? [No/yes] ";
16  std::string response;
17  std::getline(std::cin, response);
18  std::transform(response.begin(), response.end(),
19  response.begin(), ::tolower);
20  if (response != std::string("yes") and response != std::string("y")) {
21  std::cout << "Aborting." << std::endl;
22  return 1;
23  }
24  try {
25  // segwayrmp::SegwayRMP rmp(interface_type, segwayrmp::rmp100);
26  segwayrmp::SegwayRMP rmp(interface_type);
27  if (interface_type == segwayrmp::serial) {
28  rmp.configureSerial(configuration);
29  } else if (interface_type == segwayrmp::usb) {
30  switch (config_type) {
31  case 1:
32  rmp.configureUSBBySerial(configuration);
33  break;
34  case 2:
35  rmp.configureUSBByDescription(configuration);
36  break;
37  case 3:
38  rmp.configureUSBByIndex(atoi(configuration.c_str()));
39  break;
40  case 0:
41  default:
42  std::cout << "Invalid interface type provided."
43  << std::endl;
44  return 0;
45  }
46  }
48  rmp.connect();
50  while(true) {
51  rmp.move(0.1, 0);
52  usleep(100000);
53  }
54  } catch (std::exception &e) {
55  std::cerr << "Error: " << e.what() << std::endl;
56  }
57  return 0;
58 }
59 
60 void print_usage() {
61  std::cout << "Usage: " << std::endl;
62  std::cout << " segwayrmp_example usb <serial_number | description | "
63  "index> <\"00000056\" | \"Robotic Mobile Platform\" | 0>"
64  << std::endl;
65  std::cout << " or" << std::endl;
66  std::cout << " segwayrmp_example serial <serial port>" << std::endl;
67  std::cout << "Examples:" << std::endl;
68  std::cout << " segwayrmp_example usb index 0" << std::endl;
69  std::cout << " segwayrmp_example usb serial_number \"00000056\""
70  << std::endl;
71  std::cout << " segwayrmp_example serial /dev/ttyUSB0" << std::endl;
72  std::cout << " segwayrmp_example serial COM0" << std::endl;
73 }
74 
75 int main(int argc, char *argv[]) {
76  if (argc < 2) {
77  print_usage();
78  return 0;
79  }
80  if (std::strcmp(argv[1], "serial") == 0) {
81  if (argc < 3) {
82  print_usage();
83  return 0;
84  }
85  run_segway(segwayrmp::serial, std::string(argv[2]));
86  } else if (std::strcmp(argv[1], "usb") == 0) {
87  if (argc < 4) {
88  print_usage();
89  return 0;
90  }
91 
92  if (std::strcmp(argv[2], "serial_number") == 0) {
93  run_segway(segwayrmp::usb, std::string(argv[3]), 1);
94  } else if (std::strcmp(argv[2], "description") == 0) {
95  run_segway(segwayrmp::usb, std::string(argv[3]), 2);
96  } else if (std::strcmp(argv[2], "index") == 0) {
97  run_segway(segwayrmp::usb, std::string(argv[3]), 3);
98  } else {
99  print_usage();
100  return 0;
101  }
102  } else {
103  print_usage();
104  return 0;
105  }
106 }
int main(int argc, char *argv[])
void configureUSBByIndex(int device_index, int baudrate=460800)
Definition: segwayrmp.cc:320
int run_segway(segwayrmp::InterfaceType interface_type, std::string configuration, int config_type=0)
boost::shared_ptr< SegwayStatus > Ptr
Definition: segwayrmp.h:325
void connect(bool reset_integrators=true)
Definition: segwayrmp.cc:331
void setStatusCallback(SegwayStatusCallback callback)
Definition: segwayrmp.cc:715
void configureSerial(std::string port, int baudrate=460800)
Definition: segwayrmp.cc:281
void move(float linear_velocity, float angular_velocity)
Definition: segwayrmp.cc:394
void configureUSBByDescription(std::string description, int baudrate=460800)
Definition: segwayrmp.cc:308
void configureUSBBySerial(std::string serial_number, int baudrate=460800)
Definition: segwayrmp.cc:297
void setOperationalMode(OperationalMode operational_mode)
Definition: segwayrmp.cc:422
void print_usage()
void handleSegwayStatus(segwayrmp::SegwayStatus::Ptr &ss)


libsegwayrmp
Author(s): William Woodall
autogenerated on Mon Jun 10 2019 13:46:49