Created a function to check if the position is valid. This function was incorporated to send commands only if it is possible.