我正在使用集成的步进电机(带集成控制器的无刷直流伺服电机(步进电机) - NEMA 24)。我正在使用这种电机来控制燃气阀门。我希望这个电机在给定输入1时以90度的角度旋转,然后在给出输入2时返回到原始位置。首先,我需要为电机分配一个零位置,使其始终旋转90度并返回到该零点。下面是电机给出的示例代码。当我们给输入1提供高信号时,电机旋转,而当电机旋转时,另一个高信号将进一步旋转,从而覆盖先前的位置。 我是这类编程的新手,并且不知道如何处理这段代码,我希望修改这段代码,以便当我在引脚1上输入时,它应该完成第一个任务即转90度并等待下一个输入,当我在引脚2上输入时,它返回到零点。该代码将在电机内编程,输入信号将在Arduino Mega的帮助下发送。 电机的链接在这里: https://en.nanotec.com/products/1610-pd4-c6018l4204-e-01/
// in this example the position mode will be selected and started, after
the input 1 is triggered, the motor moves to a set position
(flagposition mode)
//1. Step: mapping the frequently used SDO´s
map U16 ControlWord as output 0x6040:00
map S16 ProfileVelocity as output 0x6081:00
map S32 TargetPosition as output 0x607A:00
map U32 Inputs as input 0x60FD:00
map S32 ActualPosition as input 0x6064:00
map S32 AnalogInput as input 0x3320:01
#include "wrapper.h"
//2. Step: call Main function and set the speed and mode of operation
void user()
{
od_write(0x6060,0x00, 1); // set the mode of operation to
profile position
Out.ProfileVelocity = 200; //sets the profile velocity to 200
rpm
Out.TargetPosition = 1000000000; // setting the target position
(just as a limit)
//3. Step: switch on the state machine
Out.ControlWord = 0x6; // switch to the "enable
voltage" state
do {
yield(); // waiting for the next cycle (1ms)
}
while ( (od_read(0x6041, 0x00) & 0xEF) != 0x21); // wait
until drive is in state "enable voltage"
// checking the statusword (0x6041) for the bitmask: xxxx xxxx
x01x 0001
Out.ControlWord = 0x7; // switch to the "switched on" state
do {
yield(); // waiting for the next cycle (1ms)
}
while ( (od_read(0x6041, 0x00) & 0xEF) != 0x23); // wait until
drive is in state "switched on"
// checking the statusword (0x6041) for the bitmask: xxxx xxxx
x01x 0011
Out.ControlWord = 0x4F; // switch to the "enable operation" state ,
target position relative
do {
yield(); // waiting for the next cycle (1ms)
}
while ( (od_read(0x6041, 0x00) & 0xEF) != 0x27); // wait until
drive is in state "operation enabled"
// checking the statusword (0x6041) for the bitmask: xxxx xxxx
x01x 0111
Out.ControlWord = 0x5F; // start
yield();
while(true) // endless loop
{
//3. Step: set new target position when input 1 (trigger) high
if((In.Inputs & 0x10000) == 0x10000) // if input 1
(trigger)wenn Eingang 1 (trigger) high
{
Out.TargetPosition = In.ActualPosition + 2000; //sets the
new target position depending on the actual position and analog input
Out.ProfileVelocity = 50; // new profile velocity
is 50 rpm
yield();
Out.ControlWord = 0x2F; // reset start bit 4, new
target position must be
acknowledged as new set point immediately(Bit 5)
yield();
Out.ControlWord = 0x3F; // starts the absolute positioning
yield();
while((In.Inputs & 0x10000) == 0x10000) // wait
while Input 1 still high
{
yield();
}
}
yield();
}
}