# A Neuro-Prosthetic Device for Substituting Sensory Functions during Stance Phase of the Gait
## 2 Materials and Methods
### Function 3: Software Programming and Balancing Strategies  
In this study, the Teensy 3.2 microcontroller as our device analytical core is programmed to perform two tasks. The first is to run the test-bed. We need our robot to mimic normal dog walking for the right limb during stance/swing phase recognition test as well as falling during balancing tests. To program the walking, a control loop around the joint motors is used to control the position. The block diagram for each motor-potentiometer joint controlling has been shown in Figure 7. The gait motion for each leg follows the average, representative, open loop gait based on approximated functions of joints angles found in our previous studies [17]. The legs follow the predetermined gait trajectories, but, for mimicking falling, we used the same controlling strategy for the left limb and with a separate Teensy that calculates the desired joints angles based on a modified falling function. This falling function changes the left limb joint angles over a few seconds to bring down the pelvis and mimic falling from the left side. Figure 6: Approximated hip joint angle and its angular velocity during the time of one step. Figure 7: Block diagram for mimicking normal and abnormal gait. The second microcontroller task is to serve as our device stimulation core in our tests, calculate the stimulation command required to actuate target muscles, send it to motors to correct the pelvic orientation, and gather data from IMUs to obtain information about test-bed responses to stimulation. Figure 8 shows the block diagram for this controlling function. The pelvis rotational angle, \(\alpha\), can be read by IMU #1, and \(\Delta x\) is the downward hip motion required for leveling the pelvis. If \(h\) is the width of dog pelvis, \(\Delta x\) can be found from following equation:  
\[\Delta x=h\times\tan(\alpha). \tag{1}\]  
The desired \(\Delta x\) is zero when the pelvis and consequently the dog's body is in balance. Knowing the error between actual and desired \(\Delta x\), Teensy uses the selected strategy function, \(J(\Delta x)\), to calculate desired hip, knee and hock angles as follows:  
\[\phi=J(\Delta x), \tag{2}\]  
where  
\[\phi=\left( \begin{array}{c}\beta\\ \theta\\ \varphi\end{array} \right) \tag{3}\]  
and \(\beta,\ \theta\) and \(\varphi\) are hip, knee, and hock joint angles, respectively. The actual joint angles are obtained by IMUs attached to femur, tibia, and metatarasus. Based on errors between desired and actual joints angles, Teensy runs motors CW or CCW until \(\alpha\) and, consequently, \(\Delta x\) goes close to zero. In the next sections, we discuss the strategies we use for balancing. Tables 3 and 4 summarize our balancing strategies. \(\beta_{0}\) is the initial hip joint, \(\theta_{0}\) is the initial knee joint, and \(\varphi_{0}\) is the initial hock joint angle. In Table 3, three strategies have been shown for the situation in which the falling occurs from the side with the leg in swing phase and the muscles of the dog in stance phase must be stimulated to pull the pelvis down to balance the dog body. In Table 4, we have shown two strategies that consider the dog falling from the side with the leg in stance phase. In this situation, dog muscles at stance phase are stimulated to push the pelvis up. The J function shown in Figure 8 has been calculated geometrically for each strategy and reported in Tables 3 and 4. As we have shown in our previous study [19], during the stance phase of normal dog walking, the knee joint remains almost fixed at 140 degrees. If a spinal cord-injured dog has the ability (through  
Figure 8: Block diagram for balancing. spinal cord reflexes that will not be impaired in the most common spinal cord injuries) to maintain this natural knee joint angle during stance phase of walking, the best strategy for balancing is to stimulate muscles attached to the hip and hock joint to level the pelvis and keep the knee joint unchanged. This condition can be fulfilled using strategy number 1.