## 3 The 3D Motion-Planning Algorithm
### The 3D Intraoperative Motion Planner
where \(\theta_{1}\) and \(\theta_{2}\) are randomly updated during the steering procedure, thus \(\overset{\rightarrow}{P}\) is a unit vector that represents the motion direction. The amplitudes of the sinusoidal functions are set as 8 and 5 for the obstacles and the target, respectively, such values are sufficiently large compared with the CCS needle diameter (0.432 mm). The frequency of the sinusoidal functions are 50 Hz and 600 Hz, which are sufficiently high since the insertion velocity is 1 mm/s. Through a tradeoff between the optimal extent and loop frequency, the _ValidTreeNum_ is set to 3. Based on the updated information, the intraoperative motion planner generates three trajectories and selects the best one among them. The feedback controller tracks the best trajectory and provides the current point to the intraoperative motion-planning algorithm. The trajectory is updated with a resolution of 1 mm, which is adequate considering that the insertion velocity is 1 mm/s. To emphasize the superiority of the proposed intraoperative motion planner, simulations were conducted by considering two case scenarios. Case I involves the use of the trajectory-following controller alone, and Case II involves the use of the trajectory-following controller in conjunction with the intraoperative motion planner. Each case was tested using three different target points and each test was repeated thrice to increase the credibility of the results. In both cases, an external disturbance with a magnitude of 3 mm offset was provided at the insertion depths of 61 mm and 122 mm, respectively. The simulation results are presented in Table 2, where the performance of these two cases are compared in terms of the mean, standard deviation, maximal tip position, and target errors. The data in the rows for Points 1-3 are the average values of the three repeated tests and the last row presents the overall results. According to the overall results, the case without the intraoperative motion planner yielded a path-tracking accuracy of 3.861 \(\pm\) 1.322 mm and an average target error of 4.331 mm. The case with the intraoperative motion yielded a path-tracking accuracy of 0.005 \(\pm\) 0.013 mm and an average target error of 0.093 mm. According to the comparison results, the optimal control algorithm was considerably superior to the algorithm without the intraoperative controller. This is graphically explained in Figure 9, where the red, green, and blue points denote the insertion point, initial target point, and final target point, respectively. As depicted in Figure 9a, the feedback controller can minimize the position error caused by external disturbances. However, it cannot update the desired path and steer the needle to the final target point. In Figure 9b, when the intraoperative motion planner is involved, the motion planner is able to update the intraoperative path from the point of deviation resulting from external disturbances to the target point. Therefore, the position error can not only be compensated for by the feedback controller, but can also be reduced by updating the intraoperative path using the motion planner. Moreover, the final target point can be reached using the motion planner incorporated into the optimal controller. This means that the steering system requires less control input to overcome the error, which reduces the strain on the surrounding tissues.