我试图控制微控制器中的四个不同对象(传感器、电机、旋转编码器和负责逻辑的类),其中两个功能主要是switch state
语句,一个从串行端口读取并切换一个相应的变量,以及从该变量中读取并调用函数的变量。我可以直接在 my 中从单个对象调用函数loop
,但是当我使用函数调用它们时,serialTask();
编译器会失败。这是我的标题:
这是motor.h
. 我在构造函数中使用了所有这些参数,因为我使用了两个库,它们使用这些元素来构造它们自己的对象TMC2130Stepper
,Stepper
和StepControl
#pragma once
#include <TeensyStep.h>
#include <TMCStepper.h>
#include <SPI.h>
#include <TimerOne.h>
#include <pinout.h>
#define STALL_VALUE 15
#define R_SENSE 0.11 // Match to your driver
// SilentStepStick series use 0.11
// UltiMachine Einsy and Archim2 boards use 0.2
// Panucatt BSD2660 uses 0.1
// Watterott TMC5160 uses 0.075
//BOB = 0.3
struct Motor {
public:
Motor(const int dirPinArg, const int stepPinArg, const int enabPinArg, const int chipSelectArg, const int mosiSdiArg, const int misoSdoArg, const int clkArg, float rSenseArg);
int microsteps = 8;
const uint32_t steps_per_mm = 80;
int frameRatio = (200 * microsteps) / 2.55;
int motorSpeed;
bool motorState = false;
bool isMoving = false;
bool accelerated = false;
void initializeDriver();
void setupMotor();
void accelerate();
void moveMotor();
void oneFrame();
void oneFrameSlow();
void moveMotorSlow();
bool isAccelerated();
void stepperTimer();
void setSpeed();
int spr = 16*200; // 3200 steps per revolution
TMC2130Stepper driver;
Stepper motor;
StepControl controller;
private:
};
这是我的编码器,rotary.h
:
/*
* Rotary encoder library for Arduino.
*/
#pragma once
#ifndef rotary_h
#define rotary_h
#include "Arduino.h"
// Enable this to emit codes twice per step.
//#define HALF_STEP
// Enable weak pullups
#define ENABLE_PULLUPS
// Values returned by 'process'
// No complete step yet.
#define DIR_NONE 0x0
// Clockwise step.
#define DIR_CW 0x10
// Anti-clockwise step.
#define DIR_CCW 0x20
class Rotary
{
public:
Rotary(char, char);
//Extra
int encoderTest();
// Process pin(s)
unsigned char process();
volatile int aState;
volatile int aLastState;
int counterNew;
int counterOld;
private:
unsigned char state;
unsigned char pin1;
unsigned char pin2;
};
#endif
这是我的sensor.h
:
#pragma once
#include <pinout.h>
#include <Arduino.h>
#include <open-celluloid.h>
#include <Rotary.h>
struct Sensor {
public:
Sensor(int sensorPinArg);
int readSensor();
void calibrateSensor(OpenCelluloid openCelluloidArg, Rotary rotaryArg);
void printSensorValues();
int sensorHigh{};
int sensorLow{};
};
这是另一堂课open-celluloid.h
:
#pragma once
#include <Arduino.h>
#include <TimerOne.h>
#include <HardwareSerial.h>
#include <Stream.h>
#include <Rotary.h>
#include <pinout.h>
class OpenCelluloid {
public:
OpenCelluloid();
void stepperTimer();
void homing();
void checkTrigger();
void calibrateShutter(Rotary rotaryArg);
//HardwareSerial *serial;
//HardwareSerial &serial1 = Serial;
//TimerOne *timer1;
const int sensorThreshold = 300;
int lastSensorState = 0;
uint8_t sensorState = 0; //
uint8_t stepState = 0; //
//trigger
volatile bool gateOpen{};
volatile bool trigger{};
volatile uint8_t triggerCounter{};
volatile bool sameState = true;
volatile byte threshold[8];
volatile uint8_t sum_threshold{};
volatile uint8_t gate{};
volatile uint8_t gatePrevious{};
volatile uint8_t shutterCounter{};
volatile bool boolGate{};
//volatile bool boolState = !digitalRead(sensor);
volatile bool boolState{};
volatile bool home_position{};
volatile bool startCapture;
uint8_t doFullRotation{};
int stepCount = 10000;
volatile char state;
//Rotary rotary = Rotary(5, 6);
private:
Stream *_streamRef;
TimerOne *_timerRef;
//Stepper *_motorRef;
//StepControl *_controllerRef;
};
除此之外,我还有另一个 .h 文件,其中包含以下功能:
#pragma once
#include <Arduino.h>
#include <TMCStepper.h>
#include <SPI.h>
#include <TimerOne.h>
#include <HardwareSerial.h>
#include <Stream.h>
#include "TeensyStep.h"
#include <Rotary.h>
#include <open-celluloid.h>
#include <pinout.h>
#include <motor.h>
#include <sensor.h>
#define auto_reset 20
#define start_moving_forward 21
#define start_moving_backward 22
#define keep_moving 23
#define stoping 24
#define auto_end 25
#define one_frame 26
#define hundred_frames 27
#define loading 28
#define keep_moving_slow 29
#define test 30
#define test_digital 31
#define test_analog 32
#define encoder_test 33
#define calibrate_shutter 34
#define calibrate_sensor 35
#define read_sensor 36
#define print_values 37
#define test_acceleration 38
void readSensor();
void oneFrame();
void oneFrameSlow();
void serialTask(Sensor sensorArg, Rotary rotaryArg, OpenCelluloid openCelluloidArg, Motor motorArg);
void stateSwitch(OpenCelluloid openCelluloidArg);
void encoder();
void calibrateShutter();
void testDigital(int button);
void testAnalog(int pin);
问题是文件中的函数serialTask();
如下所示functions.cpp
:
void serialTask(OpenCelluloid openCelluloidArg, Motor motorArg, Sensor sensorArg, Rotary rotaryArg) {
switch (openCelluloidArg.state) {
case auto_reset:
openCelluloidArg.state = auto_end;
break;
case start_moving_forward:
if (!motorArg.isMoving) {
//homing();
//accelerate();
motorArg.isMoving = true;
} else {
openCelluloidArg.state = keep_moving;
motorArg.isMoving = true;
}
digitalWrite(dir_Pin, LOW);
//delayMicroseconds(10000);
openCelluloidArg.startCapture = true;
break;
case start_moving_backward:
if ( !motorArg.isMoving) {
//homing();
motorArg.isMoving = true;
} else {
openCelluloidArg.state = keep_moving;
motorArg.isMoving = true;
}
digitalWrite(dir_Pin, HIGH);
//delayMicroseconds(10000);
openCelluloidArg.startCapture = true;
break;
case keep_moving:
openCelluloidArg.home_position = false;
motorArg.moveMotor();
//moveMotorPwm();
//serialFrames();
openCelluloidArg.state = keep_moving;
break;
case keep_moving_slow:
openCelluloidArg.home_position = false;
//moveMotorSlow();
openCelluloidArg.state = keep_moving_slow;
break;
case stoping:
digitalWrite(step_Pin, LOW);
digitalWrite(enabPin, HIGH);
openCelluloidArg.state = auto_end;
motorArg.isMoving = false;
digitalWrite(enabPin, LOW);
openCelluloidArg.startCapture = false;
break;
case auto_end:
openCelluloidArg.home_position = false;
break;
case one_frame:
//oneFrame();
motorArg.oneFrameSlow();
openCelluloidArg.state = auto_end;
break;
case loading:
if ( !motorArg.isMoving) {
motorArg.isMoving = true;
} else {
openCelluloidArg.state = keep_moving_slow;
motorArg.isMoving = true;
}
digitalWrite(dir_Pin, LOW);
break;
case test:
sensorArg.readSensor();
break;
case test_digital:
testDigital(encoButton);
break;
case test_analog:
testAnalog(encoButton);
break;
case encoder_test:
rotaryArg.encoderTest();
break;
case calibrate_shutter:
openCelluloidArg.calibrateShutter(rotaryArg);
break;
case calibrate_sensor:
sensorArg.calibrateSensor(openCelluloidArg, rotaryArg);
break;
case read_sensor:
sensorArg.readSensor();
break;
case print_values:
sensorArg.printSensorValues();
break;
case test_acceleration:
motorArg.accelerate();
}
};
每当我在 main 中调用此函数时loop()
,编译器都会告诉我use of deleted function 'Motor::Motor(const Motor&)'
。这是我的main.cpp
文件的样子:
#include <Arduino.h>
#include <open-celluloid.h>
#include <HardwareSerial.h>
#include <TeensyStep.h>
#include <TMCStepper.h>
#include <functions.h>
#include <motor.h>
#include <Rotary.h>
Motor motorObj(dir_Pin, step_Pin, enabPin, chipSelect, mosiSdi, misoSdo, clk, 0.11f);
Rotary rotaryObj(channelA, channelB);
Sensor sensorObj(sensor);
OpenCelluloid openCelluloidObj{};
void setup() {
pinMode(enabPin, OUTPUT);
pinMode(step_Pin, OUTPUT);
pinMode(chipSelect, OUTPUT);
pinMode(dir_Pin, OUTPUT);
pinMode(sensor, INPUT);
pinMode(led, OUTPUT);
pinMode(channelA, INPUT);
pinMode(channelB, INPUT);
pinMode(startStop, OUTPUT);
pinMode(dirSwitch, OUTPUT);
pinMode(encoButton, INPUT);
pinMode(misoSdo, INPUT_PULLUP);
pinMode(mosiSdi, OUTPUT);
pinMode(clk, OUTPUT);
digitalWrite(enabPin, LOW);
digitalWrite(dir_Pin, LOW);
digitalWrite(step_Pin, LOW);
digitalWrite(chipSelect, LOW);
digitalWrite(mosiSdi, LOW);
digitalWrite(clk, LOW);
Serial.begin(115200);
motorObj.setupMotor();
openCelluloidObj.startCapture = false;
digitalWrite(step_Pin, motorObj.motorState);
rotaryObj.aLastState = digitalRead(channelA);
openCelluloidObj.state = auto_end;
};
void loop() {
stateSwitch(openCelluloidObj);
serialTask(sensorObj, rotaryObj, openCelluloidObj, motorObj);
};
此外,我还有另一个 .h 文件pinout.h
,其中我的所有引脚都定义为常量并从其他文件中调用,但这似乎并不重要。编译器还会将我发送到我用于电机的库深处的错误,但这只发生在我调用serialTask()
. 也许重新定义有问题,我真的迷路了,非常感谢任何帮助。这是我收到的其他错误消息:
StepControlBase<a, t>::StepControlBase(const StepControlBase<a, t>&) [with Accelerator = LinStepAccelerator; TimerField = TimerField]' is protected
use of deleted function 'StepControlBase<a, t>::StepControlBase(const StepControlBase<a, t>&) [with Accelerator = LinStepAccelerator; TimerField = TimerField]'