MOVEABS not ending in Target positon

MOVEABS not ending in Target positon

The cause the problem is that a MOVEABS takes ENDMOVE of the previous move as the start point.  When we cancel the move in the MTYPE, it stops before ENDMOVE so it is not a valid start point any more.

Here is a possible solution but it is not perfect.  The end position is not exact but it is close.

PRINT""
SERVO AXIS(0) = ON
UNITS AXIS(0) = 1000
SERVO AXIS(1) = ON
UNITS AXIS(1) = 1000
WDOG = ON
MERGE = ON

SPEED = 2000
ACC(SPEED * 10)

decel_dist = SPEED ^ 2 / (2 * DECEL)

DEFPOS(0)

first_endpointx = 2000
first_endpointy = 1000
second_endpointx = 2500
second_endpointy = 1700

TRIGGER
MOVEABS(first_endpointx, first_endpointy)
WAIT LOADED
WAIT UNTIL REMAIN < 1000
GOSUB calc_xy_decel

MOVE(second_endpointx - DPOS AXIS(0) - decel_distx, second_endpointy - DPOS AXIS(1) - decel_disty)
CANCEL

' print the positions
WA(1)
PRINT "After CANCEL "; DPOS AXIS(0), DPOS AXIS(1), ENDMOVE

WAIT IDLE
PRINT "End positions  "; DPOS AXIS(0), DPOS AXIS(1), ENDMOVE

STOP

calc_xy_decel:
    decel_distx = (DEMAND_SPEED AXIS(0) * 1000) ^ 2 / (2 * DECEL)
    decel_disty = (DEMAND_SPEED AXIS(1) * 1000) ^ 2 / (2 * DECEL)
    PRINT DEMAND_SPEED * 1000
RETURN