Help installing and compiling RapaPololuMaestro in Linux?

Hi!
I am a new Mini Maestro 18 user :slight_smile: and not very experienced in linux and C++ programming.

I would like to use RapaPololuMaestro ( https://github.com/jbitoniau/RapaPololuMaestro ) in C++ in order to turn some servos but I donā€™t know why it doesnt work.

I have double checked my connections and power supply and
Iconcluded that I have done a mistake at installing the library

what I do to install it is download the repo at my home folder and then:

mkdir _build_
cd _build_
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/      

( PUT it at usr/local to install system wide??)

then I type make install

is that sufficient to install the library in my ubuntu linux?

then I write a Main.cpp file

#include "RPMSerialInterface.h"
#include <iostream>
#include <string>
#include <thread>
#include <chrono>
using namespace std;
int main( int argc, char** argv )
{
    chrono::seconds sec(5);
    // Create the interface
    std::string error_msg;
    const std::string & dev = "/dev/ttyACM0";
    RPM::SerialInterface* serialInterface = RPM::SerialInterface::createSerialInterface( dev, 9600, &error_msg);
    std::cout << error_msg;
    std::cout << "Serial Communication Started!\n";
    std::cout << serialInterface->isOpen()<<"\n";
    if ( !serialInterface->isOpen() ){
       std::cout << "Serial Communication Failed!\n";
        return -1;}
        
    // Set the value of channel 0 to 6000 quarter-of-microseconds (i.e. 1.5 milliseconds)
    std::cout << "target point 1! \n";
    serialInterface->setTargetCP( 0, 12000 );
    std::cout << "target 1 Done! \n";
    this_thread::sleep_for(sec);
    std::cout << "target point 2! \n";
    serialInterface->setTargetCP( 0, 15000 );
    std::cout << "target 2 Done! \n";
    // Delete the interface
    std::cout << "Deleting Serial Interface! \n";
    delete serialInterface;

    return 0;
}

and compile it like:

g++ -std=c++11 -O3 Main.cpp -lRapaPololuMaestro -o out

I donā€™t know if this is the correct way to compile the C++ code but the compiler produces no errors.

Then I type ./out
the programme executes but the motors donā€™t move.

I checked that the hardware works (no burned motors power supply etcā€¦) by executing MaestroControlCenter and then the motors move correctly through the graphical interfaceā€¦

if someone could tell me what I am doing wrong and how to correctly install the library and how to compile it correctly I would be gratefull.

Best regards
Thanos

Forgot to say that my minimaestro is connected through usb at my laptop and that I provided the recomended external powersupply to the servos.

Hello, Thanos.

It sounds like the Maestroā€™s serial mode setting is not configured properly, since the RapaPololuMaestro library uses the Maestroā€™s serial interface to communicate with it. By default, the Maestroā€™s serial mode is set to ā€œUART, detect baud rateā€. In that mode, the Maestro will not listen to commands from the USB virtual COM port. You would need to set the Maestroā€™s serial mode to USB Dual Port if you want to send serial commands to the Maestroā€™s Command Port.

- Amanda

Thanks for the feedback. Yes initially when I tried the control center It didnā€™t work either. Then I marked the option in the serial settings tab and everything workedā€¦
But how do I change the mode in c++?
Do I have to change something on my computer(configure a file? ) or I can pass an argument at the serialinterface CONSTRUCTOR?
Thanks in advance
Thanos

Hi
I dont know if I can set the serial setting by the Maestro control center.
I chose the Serial setting tab and then enabled the ā€œUSB Dual Portā€ then I pushed the button ā€œapply settingsā€
I also enabled the channel 0 from status tabā€¦

but still when I execute my code nothing happens. and the enabled motors get disabled during the execution of my programā€¦

Also the documentation doesnt really help meā€¦ I dont understand what should I do in order to "configure " the maestro before the first use. should I do something so that channels stay enabled for ever and the serial is at dual for ever? and if so how?

thanks in advance
Thanos

Clicking on the ā€œApply Settingsā€ button in the Maestro Control Center will save the new serial mode setting on the Maestroā€™s EEPROM, and each time the Maestro is reset or power cycled, it will reapply that setting.

I looked at your code in your first post and noticed that you are sending position values 12000 and 15000 to the servo channel 0. The Maestroā€™s native units are in quarter-microseconds and it is configured to output a standard pulse width range of 1ms to 2ms (or 4000 quarter-microseconds to 8000 quarter-microseconds) by default. By the way, 90 degrees is the standard range of motion for a servo given 1ms to 2ms pulses. Have you tried running the RapaPololuMaestroSimpleTest example under the ā€œsamplesā€ folder on its GitHub page? In your code, try changing 12000 and 15000 to something like 4000 and 6000 and let us know the outcome.

- Amanda

Hi
Thank you very much for the feedback!
I followed your advice and everything works fine for my c++ code ! :slight_smile:

I run the RapaPololuSimple test and there is no movement of the motors
but the result is:

Creating serial interface ā€˜/dev/ttyACM0ā€™ at 9600 bauds
channelValue=6012setTargetCP(2, 4000) (ret=1)
getPositionCP(2) (ret=1 position=257)
getPositionPP(12, 2) (ret=1 position=257)
setTargetCP(2, 8000) (ret=1)
getPositionCP(2) (ret=1 position=40961)
getPositionPP(12, 2) (ret=1 position=40975)
setTargetPP(12, 2, 4000) (ret=1)
getPositionCP(2) (ret=1 position=16399)
getPositionPP(12, 2) (ret=1 position=16415)
setTargetMSSCP(2, 254) (ret=1)
getPositionCP(2) (ret=1 position=40991)
getPositionPP(12, 2) (ret=1 position=40975)
setSpeedCP(2, 177) (ret=1)
setSpeedPP(12, 2, 5) (ret=1)
setAccelerationCP(2, 7) (ret=1)
setAccelerationPP(12, 2, 11) (ret=1)
setTargetPP(12, 2, 4000) (ret=1)

setTargetPP(12, 2, 8000) (ret=1)

getErrorsCP() (ret=1 errors=24862)
getErrorsPP(12) (ret=1 errors=24862)
goHomeCP() (ret=1)
goHomePP(12) (ret=1)
Deleting serial interfaceā€¦

So is this test successfull ? (I have only two motors connected)

best regards
thanos

If you did not see any movement from your servos, then the RapaPololuMaestroSimpleTest example probably did not run successfully. It looks like the code controls channel 2 on the Maestro. Did you have one of your servos connected to channel 2 when you ran the RapaPololuMaestroSimpleTest program? If so, can you change the channel number in the example code to 0 and run the code again to see if you still get no movement? I am asking you to try that since is since it sounds like channel 0 and the servo connected to it work with your C++ code, and I want to see if just channel 2 might be damaged.

- Amanda