Use commas to set off phrases at the end of the sentence that refer back to the beginning or middle of the sentence.
She went out of the room, singing merrily.
He sat on the rocking chair, reading a book.
singing/reading refer back to she/he, not 'room' and 'chair', so set them off with a comma.
compare: He sat down on the woman reading a book.
Yes - right in her lap, squashing her book!
Student or Learner