I did pass the services quiz, but I found it was rather hard to command the robot to have an exact 90 degrees rotation, and I had to adjust the parameter manually through testing.

My code for the rotation is shown below.

It performs almost a right-angle turn, but small offsets will accumulate with repetitions.

I wonder if there exists a better and more precise way to do so.

Since twist.angular.z is given in rad/s you can do this over sleeping the right amount of time for your angular speed

Yeah, I tried that before, setting twist.angular.z = 1.5708, with usleep(1000000), the offset was pretty huge, it only turned like 70 degrees. It was getting closer to 90 degrees, by decreasing the angular speed and increasing the turning duration. But still, you could tell it was not 90 degrees exactly by letting the robot move in squares multiple times since it gradually strayed away from the expected trajectory.