function for motor control