Dobot Magician: sending PWM cmd in Qt


#1

I’m trying to use my own servo connected to Dobot forearm, but I have problems with generating PWM signal in my own code. The first problem is that I can’t send to Dobot a PWM command. It looks like arm software receive it, but the servo isn’t moving (PWM signal isn’t generated). Dobot react on my signals only after I firstly move my servo using DobotStudio API. When I send PWM command using DobotStudio- everything works fine, even after hundrets of PWM commands. So after I send at least one PWM command to Dobot through DobotStudio, then Dobot arm can now receive commands from my own code.

So after I can send PWM commands to Dobot arm, the second problem appers: Dobot arm doesn’t always move my servo properly- it looks like genereted PWM signal from arm must be sometimes somehow wrong, because the servo sometimes shakes for a while, or servo opens widely (sometimes after few PWM commands, sometimes after hundreds of them). I guess something is wrong with my code, because everything works fine in DobotStudio. Could you check what may be wrong In my code? The code has been added to your QT demo code for 1 arm:

void MainWindow::on_pwmBtn_clicked()
{
    float pwm = ui->pwmLineEdit->text().toFloat();
    if (pwm >= 3.f && pwm <= 12.f) {
        IOPWM servo;
        servo.address = 4;
        servo.frequency = 50; // [Hz]
        servo.dutyCycle = pwm; // [%]
        int setResult = SetIOPWM(&servo, false, NULL);
        if (setResult == DobotCommunicate_NoError) {
            IOPWM checkServo;
            int getResult = GetIOPWM(&checkServo);
            if (getResult == DobotCommunicate_NoError) {
                ui->pwmAdressLbl->setText(QString::number(checkServo.address));
                ui->pwmFrequencyLbl->setText(QString::number(checkServo.frequency));
                ui->pwmDutyCycleLbl->setText(QString::number(checkServo.dutyCycle));
            } else qDebug() << "error: failed to GetIOPWM:" << getResult;
        } else qDebug() << "error: failed to SetIOPWM:" << setResult;
    } else ui->pwmLineEdit->clear();
}

I receive no errors. Same PWM parameters works on DobotStudio. This soft doesn’t works on IO ports: 4, 6 and 8. Data received from GetIOPWM are strange: adress = 34, frequency = 0, dutyCycle = 0.