I'm making a program in C for the gertbot, and i would like to use the linux method get_motor_missed(brd,mot)
Method in linux :
Code: Select all
#
# Get motor missed steps from board
#
# return list with on element: missed steps
# returns empty list on fail
#
def get_motor_missed(brd,mot) :
id = (brd<<2) | mot
wrtbuf = [PRE, CMD_MOT_MISSED, id, POST, POST, POST, POST, POST, POST]
os.write(filehandle,bytes(wrtbuf))
# returns 8 bytes:
# ID, CMD,
# missed:MS, missed:MM, missed:LS
# three times 0
termios.tcdrain(filehandle)
ok , rec_data = read_uart(8)
if (not ok) : # or rec_data[0]!=CMD_MOT_MISSED or rec_data[1]!=dest) :
return []
motor_data = [0]*2
motor_data[0] =(rec_data[2]<<16) + (rec_data[3]<<8)+rec_data[4]
# Next should be zero
motor_data[1] =(rec_data[5]<<16) + (rec_data[6]<<8)+rec_data[7]
return motor_data
to know: the command to ask for the steps is not included in the C-drives and needs to be added manually.
Code: Select all
#define CMD_MOT_MISSED 0x1C //is not included in C-drives
void get_motor_missed()
{
char *reply;
int bytes,error;
move_stepper(board_XY, MOTOR_X_CHANNEL, STEPS);
stop_stepper(board_XY, MOTOR_X_CHANNEL, GB_STOP_OFF);
gb_command7[1] = CMD_MOT_MISSED;
gb_command7[2] = board <<2;
gb_command7[3] = CMD_STOP_VAL;
gb_command7[4] = CMD_STOP_VAL;
gb_command7[5] = CMD_STOP_VAL;
int i = write_uart(gb_command7,7);
bytes = read_uart(&reply, 8);
printf("Result: bytes %i data %p", bytes, &reply);
}
Result examples
Code: Select all
Example 1: STEPS = 200
Result: bytes 8 data 0x7ee4f9c8
Example 2: STEPS = 200
Result: bytes 8 data 0x7ea779c8
Example 3: STEPS = 200
Result: bytes 8 data 0x7ecc49c8