51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
#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;
|
||
};
|