User Tools

Site Tools




void setMotorPos (u8 motionID, u8 stCh, u32 position)

motionID : The ID of the Motion Control Module
stCh: The channel on the Motion Control Module (0 or 1)
position: The value of the motor's current position)

Sets the motor's current position to position. The motor's starting position (home) can be set by moving the motor to it's home and calling setMotorPos with position equal to 0. This method essentially calibrates the motor to its position in the physical world. The motor is identified by id of the Motion Control Module, motionID, and the module's channel, stCh.

It is recommend that this function be called at least once when the system is powered on or initialized.

#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/setmotorpos/index.txt · Last modified: 2016/04/14 11:07 (external edit)