This invention relates to compounds that are agonists of the muscarinic M1 and/or M4 receptor and which are useful in the treatment of diseases mediated by the muscarinic ?1 and M4 receptors. Also provided are pharmaceutical compositions containing the compounds and the therapeutic uses of the compounds. Compounds provided are of formula (I) where p; q; X1; X2; Y; R1; R2; R3; R4; R5 and R6 are as defined herein.