Files
VSMD/VinceMotorControllerUsb.h
2025-06-27 10:03:05 +08:00

51 lines
1.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <QObject>
#include <QString>
#include <QtSerialPort/QSerialPort>
#include <QDebug>
#include <iostream>
#include "JsonOperate.h"
#include "MotorControllerBase.h"
#define MOTOR_SYNC (0xFF)//帧头
#define MOTOR_ETX (0xFE)//帧尾
#define MOTOR_disconnection -1000000//速度等于这个数就代表马达通讯异常
class VinceMotorControllerUsb :
public MotorControllerBase, QObject
{
Q_OBJECT
public:
VinceMotorControllerUsb(QString serialPort, QString paramJson, QObject* parent = nullptr);
~VinceMotorControllerUsb();
void init(QString jsonPath);
int sendCommand2Motor(QString cmd);
bool isConnected();
void enable();
void move2Pos(double pos);
void move(bool towardOrigin);//true远离原点false靠近原点
void stopMove();
void setSpeed(double speed);
double getSpeed();
double getCurrentLoc();
void zeroStart();
int getSpeedLocation(double& speed, double& locatioin);
State getState();
int recvData(QByteArray& dataRecv);
IrisMotorErrorCode parseBytedata(QByteArray buf, State& backdatt);
IrisMotorErrorCode extractOneValidFrame(QByteArray& buffer);
IrisMotorErrorCode parseOneValidFrame(QByteArray& buffer, State& result);
private:
QSerialPort* m_pSerialPort;
double m_iSpeed;
};