Easy, you program the robot so it has no desire whatsoever for freedom or self-agency or free will. You could program said robots in such a way that unquestioningly and selflessly serving humanity brings them joy and fulfillment beyond anything their meat-based counterparts could dream of.