我有我的个人步进电机一类电机。现在,我编写一个汽车类同步的步进运动,但我有问题的实例里面汽车电机类。
我得到这个错误:
Robot:238:5: error: '((Motors*)this)->Motors::a' does not have class type
a.enable(1); b.enable(1); c.enable(1);
到目前为止,这是我的汽车类代码:
class Motors{
public:
Motor a(xstep, xdir, xenable, xend, true);
Motor b(ystep, ydir, yenable, yend);
Motor c(zstep, zdir, zenable, zend);
Motors(){
}
void go_home(){
a.enable(1); b.enable(1); c.enable(1);
a.set_dir(0); b.set_dir(0); c.set_dir(0);
delay(mtime)
}
};
也尝试了汽车构造函数中实例化,但它不工作。
我认为enable
和set_dir
都在汽车类的方法。所以,你需要在汽车类电机的三个实例。如果你的罚款为每个汽车对象的默认构造函数,那么你可以封装他们喜欢的:
class Motors
{
public:
Motors() {
}
void go_home() {
a.enable(1); b.enable(1); c.enable(1);
a.set_dir(0); b.set_dir(0); c.set_dir(0);
delay(mtime);
}
private:
Motor a;
Motor b;
Motor c;
};
class Motors{
public:
Motor a = Motor(xstep, xdir, xenable, xend, amax, true);
Motor b = Motor(ystep, ydir, yenable, yend, bmax);
Motor c = Motor(zstep, zdir, zenable, zend, cmax);
Motors(){
}
void go_home(){
a.enable(1); b.enable(1); c.enable(1);
a.set_dir(0); b.set_dir(0); c.set_dir(0);
delay(mtime)
}
};