To use feedback speed control instead of direct voltage control, consider the
set_differential_speed
messages rather than use callbacks, you may use the
unhandled messages. For more details on using the Python driver, see the included documentation and
examples.
This code is similar to the Python code, except that it uses the built in speed controller to implement a
velocity ramp as opposed to the Python demo's use of the raw motor control functionality the protocol
also provides.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
#include <typeinfo>
#include "clearpath.h"
using namespace std;
int main(int argc, char *argv[]) {
/* Configure the serial port */
const char* port = (argc == 2) ? argv[1] : "/dev/ttyUSB0";
clearpath::Transport::instance().configure(port, 3 /* max retries*/);
/* Subscribe to some interesting data */
clearpath::DataSystemStatus::subscribe(1);
clearpath::DataSystemStatus * cur_status = NULL;
/* Ramp speed to 0.6m/s over 6 seconds.
* We use the 1Hz system status message for timing, so we want to
* begin by waiting for the first message, which is sent shortly
* after the beginning of the subscription */
cur_status = clearpath::DataSystemStatus::waitNext();
cout << *cur_status << endl;
delete cur_status;
for(int i=1; i<=6; ++i) {
// Set motor speed
clearpath::SetVelocity(0.1*i, 0.0, 1.0).send();
/* Wait for the next system status message to arrive */
while(!(cur_status = clearpath::DataSystemStatus::popNext()));
cout << *cur_status << endl;
delete cur_status;
}
/* Terminate subscriptions */
clearpath::DataSystemStatus::subscribe(0xffff);
return 0;
}
Clearpath Robotics Inc. ©2011 All Rights Reserved.
or
set_velocity
// want getchar()
messages. Also, if you would prefer to poll for received
get_waiting
method to receive a list of
17
Need help?
Do you have a question about the HUSKY A200 and is the answer not in the manual?