75 lines
2.2 KiB
C++
75 lines
2.2 KiB
C++
#include "color.h"
|
||
#include <glog/logging.h>
|
||
#include <iostream>
|
||
#include <map>
|
||
#include <queue>
|
||
#include <shared_mutex>
|
||
#include <sstream>
|
||
#include <stdio.h>
|
||
#include <string>
|
||
#include <thread>
|
||
#include <time.h>
|
||
extern "C" {
|
||
#include <modbus/modbus.h>
|
||
//#include <wiringPi.h> // 树莓派GPIO库
|
||
// src中202行记得修改
|
||
}
|
||
|
||
class ConveyorBeltControlUnit {
|
||
private:
|
||
// 所有的输入端口配置为内部上拉,低有效
|
||
// 悬空时为高,视为逻辑0
|
||
// 外部拉低时,视为逻辑1
|
||
const int IN_LOGIC_0 = 1;
|
||
const int IN_LOGIC_1 = 0;
|
||
|
||
// 输出端口为Push-Pull模式
|
||
// 逻辑开时输出高电平
|
||
// 逻辑低时输出低电平
|
||
const int OUT_ON = 1;
|
||
const int OUT_OFF = 0;
|
||
|
||
const int BTN_DIRSWITCH = 26; // 运行方向切换按钮
|
||
const int BTN_START = 23; // 启动按钮
|
||
const int BTN_STOP = 24; // 停止按钮
|
||
const int BTN_ESTOP = 11; // 急停
|
||
|
||
int INPUT_FSENSOR = 28; // 正转边沿传感器
|
||
int INPUT_RSENSOR = 29; // 反转边沿传感器
|
||
int OUT_FRUN = 14; // 正向运行输出
|
||
int OUT_RRUN = 10; // 反向运行输出
|
||
|
||
// 定义事件
|
||
const int EVENT_ESTOP_PUSH = 0; // 急停按下(电平触发)
|
||
const int EVENT_STOP_PUSH = 1; // 停止按下(电平触发)
|
||
const int EVENT_FSENSOR_OBSTRUCT = 2; // 正转传感器触发(电平触发)
|
||
const int EVENT_RSENSOR_OBSTRUCT = 3; // 反转传感器触发(电平触发)
|
||
const int EVENT_DIRSWITCH_RISING = 4; // 切换运转方向(逻辑上升沿触发)
|
||
const int EVENT_START_RISING = 5; // 开始运行(逻辑上升沿触发)
|
||
|
||
// 定义unit工作状态
|
||
const int RUNNING = 1;
|
||
const int STANDBY = 0;
|
||
|
||
int current_start_signal;
|
||
int current_stop_signal;
|
||
int currentMode;
|
||
float speed;
|
||
int workState;
|
||
std::map<int, std::map<int, int>> modeSwitchMap;
|
||
void action(int event);
|
||
std::string modeToString();
|
||
int getWaitCount();
|
||
|
||
public:
|
||
void conveyorBeltWorkingProcess();
|
||
int init();
|
||
int setSpeed(float speed);
|
||
int setDirection(int direction);
|
||
int startConveyorBelt();
|
||
int stopConveyorBelt();
|
||
int getWorkState();
|
||
ConveyorBeltControlUnit(/* args */);
|
||
~ConveyorBeltControlUnit();
|
||
};
|