## 2 Materials and Methods
### Guide Positioning Control
The second method is the S-curve speed control, as shown in Figure 23. The speed change at the beginning of acceleration/deceleration is slower and increases gradually. The speed change slows down again when approaching the end of acceleration/deceleration. Several possible S-curves have been proposed, including the sine curve, quadratic curve, cyclic curve, and cubic curve. In this study, a parabolic curve, as described in [16], is used. Equations (6)-(8) are the functions for acceleration, velocity, and moving distance. The values of \(\alpha\) and \(\beta\) are constrained by \(\beta=\alpha t_{2}\). Since the stepping motor is driven by the pulses from the microcontroller, the desired number of pulses in each discrete time is determined on the basis of Equation (10), where \(\theta_{e}\) is the step angle of the stepping motor, and r is the axle radius of the stepping motor. Figure 21: Schematic diagram of stepping motor control. Figure 20: Classification of stepping motors. Two methods are used for controlling the motor positioning. First, the distance between two adjacent gallipots is measured, the number of pulses (steps) required for the stepping motor to move this distance is calculated, and the necessary steps from the starting point to the destination are then utilized for speed control using either trapezoidal or S-curve control to prevent stalling and overshoot. Second, limit switches are used in order to detect the correct positions. These two methods could support each other. Both counting steps and receiving the signal from the limit switch can be used to determine whether the block reaches the destination or not. If both determinations are successful, accurate positioning has been achieved. If the signal from the limit switch stop the motor is received first to, the steps counted by the software are less than the pre-set steps, and overshoot occurs, although the positioning is still accurate. If the steps counted by the software reach the pre-set steps first but the limit switch has not been activated, stalling occurs, the positioning by the software is not accurate, and troubleshooting is needed. Figure 24 displays the flow chart of the speed and positioning control for the guide motor. The weighing module equipped with a controller is shown in Figure 25. The deformation of the load arm caused by the measured object on the weighing module changes the resistance of the strain gauge and results in a voltage signal which is then amplified through the HX711 ADC conversion module. The readout converted by the software is the weight of the object. The weighing element is able to read up to 1 kg, with a resolution of 0.01 g. The application of this weighing module to the dispensing of scientific Chinese medication powder could be used to accurately measure powder weight to avoid excess powder waste, decrease the manpower required for weighing and packing traditional Chinese medicine, accelerate the dispensing process in pharmacies, and establish systematic dispensing and weighing process records, thus promoting precise medical treatment. Figure 26 displays the operation process of a weighing module, and Figure 27 shows the weighing control process. The controller reads the data transmitted from the weighing module and compares this with the set value in order to judge whether the set weight has been achieved; if not, the rotation motor continues operation until the  
Figure 24: Flowchart of speed and positioning control for guide motor. weight appears within the target weight range. This automatic weighing aims to reduce the workload of pharmacists for scientific Chinese medication dispensing. Figure 27: Weighing control process. Figure 25: Weighing module. Figure 26: Weighing module operation process. Weighing Mechanism Retraction Control  
The weighing mechanism on the linear guide is a translation mechanism. For convenient operation, the weighing mechanism is detached from the gallipot base on the medicine shelf.