Diy attitude controller for quadopter

I wanted to make my own attitude controller for quadrotor. I am not able to find a way to send command to the motors. I tried to find a way to
do this. I am now able to set the throttle input to the motors but the motor commands for pitch, roll and yaw rotation is not yet possible. I created a new mode and I have figured out to set the desired throttle following code is to be executed

attitude_control->set_throttle_out_unstabilized(0.25, 1, g.throttle_filt);

where 0.25 is the commanded throttle.

but finding such code for pitch, roll and yaw motions is not yet possible to me. I tried another approach of writing directly to motors without the mixer using following lines of code.

hal.rcout->write(0, 1500);

this sets channel 0 to pwm duty cycle of 1.5ms
but the pwm duty cycle measured by oscilloscope is not uniform. It gets changed in between and then return to expected value.

How this can be done? any help regarding this will be highly appreciated.