Dear friend,
You can use get_cgpio_digital the get the value of the IO, judge if the IO has changed, if yes control RPY via set_position/set_servo_angle method. We provide a relative parameter to do relative motion.
Below is a simple demo just for your reference, CI1 mapping x+10, CI2 mapping y+10.

Best regards,
Minna