Frist, I want to use the SDK(RapaPololuMaestro-master), it install in ubuntu, however I don’t find the address of library por Qt
Now, use the class QSerialPort for open and write the COM.
But 'device not open’
In the guide Section 10,write that “You will need to set the Maestro’s serial mode to be either ‘USB Dual Port’ or ‘USB Chained’”, but still ‘device not open’
//servocontroller.h
#ifndef SERVOCONTROLLER_H
#define SERVOCONTROLLER_H
//#include <string>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
class ServoController
{
public:
virtual ~ServoController(); // Destructor
// Create a concrete platform-specific SerialInterface.
// Return NULL if the interface couldn't be created and set the optional error message.
void createSerialPort(const QString &portName, unsigned int baudRate);
//createSerialPort(const QString &portName, unsigned int baudRate);
// Set the target position of a channel to a given value in 0.25 microsecond units
void setTarget( unsigned char channelNumber, unsigned short target );
//setTarget( unsigned char channelNumber, unsigned short target );
private:
static const unsigned short mMinChannelValue = 4000;
static const unsigned short mMaxChannelValue = 8000;
char command[4];
QSerialPort* myCom;
};
#endif // SERVOCONTROLLER_H
[code]
//servocontroller.cpp
#include “servocontroller.h”
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
void ServoController::createSerialPort( const QString &portName, unsigned int baudRate)
{
myCom= new QSerialPort();
myCom->setPortName(portName);
myCom->open(QIODevice::ReadWrite);
myCom->setBaudRate(baudRate);
myCom->setDataBits(QSerialPort::Data8);
myCom->setParity(QSerialPort::NoParity);
//myCom->setStopBits(QSerialPort::OneStop);
myCom->setFlowControl(QSerialPort::NoFlowControl);
}
ServoController::~ServoController()
{
myCom->close();
}
void ServoController::setTarget( unsigned char channelNumber, unsigned short target )
{
if (target<mMinChannelValue ){
target=mMinChannelValue;
}
if(target>mMaxChannelValue){
target=mMaxChannelValue;
}
command[0]=0x84;
command[1]=channelNumber;
command[2]=target & 0x7F;
command[3]=(target >> 7) & 0x7F;
myCom-> QSerialPort::write(command);
}[/code]
// main.cpp
#include <servocontroller.h>
int main()
{
QString portName = "/dev/ttyACM0";
unsigned int baudRate=9600;
ServoController com;
com.createSerialPort(portName, baudRate);
while(true){
com.setTarget(0x02,6000);
}
}
error: QIODevice::write (QSerialPort): device not open