Thank you for the nicely thorough history you've provided. The confluence of being testy/barking/behavioral issues and his "hallucinatory" behavior shouldn't be overlooked. His looking at the ground and barking is akin to air-snapping and star-gazing in our dogs - hallucinatory behavior thought to represent obsessive-compulsive disorder (OCD) by behaviorists and partial seizure activity by neurologists.
OCD is defined as mood/behavioral disorders characterized by repetitive, invariant, patterned behaviors that are exaggerated in intensity, frequency, and duration given the inciting stimuli (i.e., expressed out of context). The behavior interferes with health and well-being. Earlier in the course you may have been able to stop the behavior, but that may not be the case at this time. he may hide (to perform the behavior), become aggressive when you attempt to stop it, or may begin avoiding you.
His staring at the ground and then barking may suggest partial seizures or, at least, dysphoria (a state of unease) and so, consultation with a specialist veterinary neurologist (please see here: www.acvim.org) should be considered. All cases of OCD warrant intervention which is individualized and based on frequency and severity of clinical signs. Treatment is usually a combination of behavioral and environmental modification and psychotropic medication. The goal is to minimize and if possible eliminate bouts of compulsive behavior and the concomitant anxious states that accompany them.
In general, we need to identify and eliminate trigger events/situations. No punishment should ever be used since it can heighten anxiety and worsen the problem. If possible, these pets can be redirected to an alternative and incompatible behavior (such as licking food from a toy instead of licking the skin) if the redirection doesn't make the pet more anxious. Pets should be calmly rewarded for any spontaneous calm behavior. Keeping a structured daily routine helps decrease anxiety. The most successful medications used in the treatment of OCD in people include SSRIs such as fluoxetine (Prozac) and clomipramine (Clomicalm). Typically, psychotropic therapy is necessary for longer periods of time than other anxiety-based disorders (months to years depending upon severity and how long the disorder has been ongoing). Lifelong medication use isn't unusual in severe cases.
Please respond with further questions or concerns if you wish.