User Tools

Site Tools

한국어

moacon:motorstat:index

motorStat

u32 motorStat (u8 motionID, u8 stCh)

motionID : The ID of the Motion Control Module
stCh: The channel on the Motion Control Module (0 or 1)
returns the number of pulses left to send to the motor.

Returns the number of pulses left to send to the motor from the last call to motorMove. The motor is identified by id of the Motion Control Module, motionID, and the module's channel, stCh.

When motorMove is called, the Motion Control Module sends a stream of pulses that cause the motor to move. motorMove essentially tells the Motion Control Module how many pulses to send in total. If the stream of pulses is rather long and/or the wavelength of the pulse (the motor's speed) is rather slow, it may take some time for the motor to arrive at its final position. motorStat can be used to determine if the motor is moving and/or how much longer the motor has left to move by returning how many pulses the Motion Control Module has left to send.

The following program moves a motor to position 100,000, waits for the movement to finish, and then moves the motor back to its starting position.

#include "moacon500.h"
 
//Waits for motor to finish moving
 
void motorWaitToFinish(u8 motionId, u8 stChannel)
{
 
 //Get the current number of pulses left to send
 u32 pulseCount = motorStat(motionId, stChannel);
 
 //While there are still pulses remaining (i.e. the motor is still moving)
 while(pulseCount > 0)
 {
     //Get the current number of pulses left to send
     pulseCount = motorStat(motionId, stChannel);
 
     //Print the number of pulses remaining to the debug console
     printf("%d pulses remaining\r\n", pulseCount);
     delay(500);                             //Give the CPU a break.
 }
}
 
void cmain(void)
{
     motorSetup(0, 0, 500, 5000, 1000);      //Initialize the motor
     setMotorPos(0,0,0);                     //Current position is starting position
     motorMove(0,0,100000);                  //Move the motor to position 100,000
     motorWaitToFinish(0,0);                 //Wait for the motor to finish moving
     motorMove(0,0,0);                       //Move motor back to starting position
     motorWaitToFinish(0,0);                 //Wait for the motor to finish moving
}

go MOACON home

moacon/motorstat/index.txt · Last modified: 2016/04/14 11:07 (external edit)