所以我一直在尝试创建3个“ accelstepper”对象。 This is a screenshot of my code in case the code section doesn't appear。另外,this is a screenshot of the file "stepper_directory.h"
#include <mbed.h>
#include "stepper_directory.h"
//Include accelstepper library
#include <AccelStepper.h>
//Create accelstepper object for the Z-Axis actuator
AccelStepper zaxis(uint8_t interface = AccelStepper::DRIVER, uint8_t zstep = ZSTEP, uint8_t zdir = ZDIR);
//Create accelstepper object for the theta axis actuator
AccelStepper taxis(uint8_t interface = AccelStepper::DRIVER, uint8_t tstep = TSTEP, uint8_t tdir = TDIR);
//Create accelstepper object for the magnet actuator
AccelStepper maxis(uint8_t interface = AccelStepper::DRIVER, uint8_t mstep = MSTEP, uint8_t mdir = MDIR);
这是我使用的头文件“ stepper_directory.h”
#ifndef _STEPPER_DIRECTORY
#define _STEPPER_DIRECTORY
#include "PinNames.h"
//Pin Definitions
#define ZSTEP PA_7
#define ZDIR PA_0
#define TSTEP PA_8
#define TDIR PA_1
#define MSTEP PA_9
#define MDIR PA_2
我试图在main.cpp的主代码中设置一个步进器,如下所示:
int main() {
// put your setup code here, to run once:
zaxis.setMaxSpeed(188000);
while(1) {
// put your main code here, to run repeatedly:
}
}
但是platformIO编译器抛出了以下几行:
src\main.cpp: In function 'int main()':
src\main.cpp:17:7: error: request for member 'setMaxSpeed' in 'zaxis', which is of non-class type 'AccelStepper(uint8_t, uint8_t, uint8_t)
{aka AccelStepper(unsigned char, unsigned char, unsigned char)}'
zaxis.setMaxSpeed(188000);
^~~~~~~~~~~
*** [.pio\build\nucleo_f410rb\src\main.o] Error 1
我一直在尝试搜索对象实例有什么问题,但无济于事。如果有人可以解释这有什么问题,我将不胜感激。 This is a screenshot of the error in question
答案 0 :(得分:0)
问题在这里。
//Create accelstepper object for the Z-Axis actuator
AccelStepper zaxis(uint8_t interface = AccelStepper::DRIVER, uint8_t zstep = ZSTEP, uint8_t zdir = ZDIR);
这是一个函数声明。它接受三个参数并返回AccelStepper
。您无法使用此行代码初始化AccelStepper
的实例。
我假设AccelStepper
的构造函数是这样的:
AccelStepper AccelStepper(uint8_t interface, uint8_t zstep, uint8_t zdir);
您可以通过以下方式初始化实例:
AccelStepper zaxis(AccelStepper::DRIVER, ZSTEP, ZDIR);