6 channel Maestro 'device not open' in ubuntu&Qt

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

Before, I want to use the SDK(RapaPololuMaestro-master), and have been installed.
However, I don’t find the address of library file of SDK(RapaPololuMaestro-master) for Qt

Now, use the class QSerialPort(Qt), but 'device not open’
I try to use all Maestro’s serial mode, “USB Dual Port”, “USB Chained”, and “UART”, but don’t use

[code]//servocontroller.h
#ifndef SERVOCONTROLLER_H
#define SERVOCONTROLLER_H
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>

class ServoController
{
public:
virtual ~ServoController();
void createSerialPort(const QString &portName, unsigned int baudRate);
void 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]

[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]

[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);
}

}
[/code]

error: QIODevice::write (QSerialPort): device not open

Hello. I am sorry you are having trouble using the Micro Maestro 6-Channel USB Servo Controller with RapaPololuMaestro in Ubuntu. Please note that even though we link to that library from the Maestro user’s guide, it is a third-party library and our support for it is limited. Also, I am not familiar with the QSerialPort class.

The error “device not open” makes me think there was an error when you tried to open /dev/ttyACM0. Can you run the following two commands and post their output here? These commands will help us check that the serial port exists and that your user has permission to access it.

ls -l /dev/ttyACM*
groups

–David

[quote=“DavidEGrayson”]Hello. I am sorry you are having trouble using the Micro Maestro 6-Channel USB Servo Controller with RapaPololuMaestro in Ubuntu. Please note that even though we link to that library from the Maestro user’s guide, it is a third-party library and our support for it is limited. Also, I am not familiar with the QSerialPort class.

The error “device not open” makes me think there was an error when you tried to open /dev/ttyACM0. Can you run the following two commands and post their output here? These commands will help us check that the serial port exists and that your user has permission to access it.

ls -l /dev/ttyACM*
groups

–David[/quote]

I know why the device not open, es problem of root.

sudo su

But I can’t control the servo motor.
Compact protocol: 0x84, channel number, target low bits, target high bits

char command[4]; command[0]=0x84; command[1]=0x01; command[2]=target & 0x7F; command[3]=(target >> 7) & 0x7F;
But target es ‘unsigned short’ in SDK, is it correct? Or use hex?

[quote=“DavidEGrayson”]Hello. I am sorry you are having trouble using the Micro Maestro 6-Channel USB Servo Controller with RapaPololuMaestro in Ubuntu. Please note that even though we link to that library from the Maestro user’s guide, it is a third-party library and our support for it is limited. Also, I am not familiar with the QSerialPort class.

The error “device not open” makes me think there was an error when you tried to open /dev/ttyACM0. Can you run the following two commands and post their output here? These commands will help us check that the serial port exists and that your user has permission to access it.
–David[/quote]

the data es correct now, but can’t control servo motor.
I use the Compact protocol: 0x84, channel number, target low bits, target high bits
And UART 9600, it is correct, isn’t it???

If use the Pololu protocol: 0xAA, device number, 0x04, channel number, target low bits, target high bits,
What is the device number?

It is fine to make the “target” variable be an unsigned short, because that is a 16-bit integer on most systems. It does not matter whether you use hex or decimal notation in the source code of your program; those are just two different ways of writing numbers. What matters is the actual values of the bytes you are sending.

The device number in the Pololu protocol is an arbitrary number you can assign to your Maestro that allows you to control multiple Maestros that are on the same serial line. Since you just have just one Maestro in this system, I recommend using the compact protocol (not the Pololu protocol) to keep things simple.

Since you are controlling the Maestro with its USB virtual serial ports, the baud rate you choose should not matter; 9600 is fine.

It sounds like you were able to solve your “device not open” problem but now your servo is not actually moving. Could you try controlling your servo from the Status tab of the Maestro Control Center and see if that works? If it does work, then we know your hardware setup is okay and there is an issue either with the Maestro serial settings or your code. You mentioned this already, but you should make sure that the Maestro’s serial mode is set to “USB Dual Port” or “USB Chained”. You should make sure you have connected an appropriate servo power supply to your Maestro. Also, I recommend that you try commanding the servo to move to two different locations with a delay between the commands. If you are just sending one Set Target command and the servo is already at the target position, it won’t move.

If you continue to have trouble, please post your Maestro settings file, your code, a description of your power supply, and some photos of your setup.

–David