C++ interface for Parallax Servo Controller USB to Computer
Hi all,
I am a rather novice user of servo controller and would ask some noob question.
I have a Parallax Servo Controller USB and need to write a C++ code to control few servos to make my robot move.
I found a software (PSCI) on parallax website in which mouse is used to control the servos by using sliders on GUI.
Is there a library or a piece of code written in CPP/C which I can use to programatically control the servos on various channels to accomplish my task.
I tried my best to look for one for last 2 hours but couldn't find
.
I would highly appreciate any help in this regard.
-Atul
I am a rather novice user of servo controller and would ask some noob question.
I have a Parallax Servo Controller USB and need to write a C++ code to control few servos to make my robot move.
I found a software (PSCI) on parallax website in which mouse is used to control the servos by using sliders on GUI.
Is there a library or a piece of code written in CPP/C which I can use to programatically control the servos on various channels to accomplish my task.
I tried my best to look for one for last 2 hours but couldn't find
I would highly appreciate any help in this regard.
-Atul

Comments
This forum would not accept a cpp file extension so I changed it to txt.
#include <iostream> #include <boost/asio.hpp> using namespace std; using namespace boost; int main(int argc, char* argv[]) { try { boost::asio::io_service io; boost::asio::serial_port serial(io,"COM6");// set your own com port, linux people can use /dev/ttyS1 or something like that serial.set_option(boost::asio::serial_port_base::baud_rate(2400));//I found parallax controller works at 2400 baud rate std::string comd = "!SC";//preamble char c = 5;//set channel char r = 0;//set ramp value char l = 250;//lower char h = 0;//higher char ret = '\x0D';//end of line character //prepare the command as below comd += c; comd += r; comd += l; comd += h; comd += ret; //run the commandboost::asio::write(serial,boost::asio::buffer(comd.c_str(),comd.size())); //sleep for command to execute Sleep(10); //read the data from controller and print vector<uint8_t> buf(8); try { size_t len = boost::asio::read(serial, boost::asio::buffer(buf)); cout<<"Data returned by servo:"<<endl; cout<<"Channel="<<(int)buf.at(3)<<"\n"; cout<<"Ramp="<<(int)buf.at(4)<<"\n"; cout<<"L="<<(int)buf.at(5)<<"\n"; cout<<"H="<<(int)buf.at(6)<<"\n"; } catch (boost::system::system_error &err) { cout<<"Error in reading data from the servo:"<<err.what()<<"\n"; } //close the connection serial.close(); } catch(boost::system::system_error& e) { cout<<"Error: "<<e.what()<<endl; return 1; } }