Estimation of Knee Assistive Moment in a Gait Cycle Using Knee Angle and Knee Angular Velocity through Machine Learning and Artiﬁcial Stiffness Control Strategy (MLASCS)

: Nowadays, many people around the world cannot walk perfectly because of their knee problems. A knee-assistive device is one option to support walking for those with low or not enough knee muscle forces. Many research studies have created knee devices with control systems implementing different techniques and sensors. This study proposes an alternative version of the knee device control system without using too many actuators and sensors. It applies the machine learning and artiﬁcial stiffness control strategy (MLASCS) that uses one actuator combined with an encoder for estimating the amount of assistive support in a walking gait from the recorded gait data. The study recorded several gait data and analyzed knee moments, and then trained a k-nearest neighbor model using the knee angle and the angular velocity to classify a state in a gait cycle. This control strategy also implements instantaneous artiﬁcial stiffness (IAS), a control system that requires only knee angle in each state to determine the amount of supporting moment. After validating the model via simulation, the accuracy of the machine learning model is around 99.9% with the speed of 165 observers/s, and the walking effort is reduced by up to 60% in a single gait cycle.


Introduction
Too much walking, running, sitting, and standing can cause body pain, particularly knee pain. It is quite common because the knees carry the whole upper body weight in most human movements. If people have knee discomfort, it will significantly impact their daily lives, such as trouble walking/running/sitting, etc., or a lack of confidence in doing basic chores [1]. Furthermore, several people have knee impairments, such as muscle weakness, pain, and paralysis resulting from a spinal cord injury, severe injury, or other syndromes [2,3].
To handle knee problems, many knee devices have been built. Knee reinforcement devices are usually mechanical or electromechanical in general. Importantly, the goal of the knee reinforcement device is to increase the user's loading capacity or to decrease the user's metabolism during various mobility tasks [4]. When the user wears the device, it should be comfortable and supportive [5].
Control techniques are necessary during knee exoskeleton development in every actuation type because of the physical connection between the wearer and the device. The assistive moment can be generated corresponding to the wearer's movements and intention with the control strategy for ensuring the safety and comfort of the wearer. Different control strategies for knee exoskeletons have been suggested, for example, the position-based trajectory tracking control, the assist-as-need control, and the bioelectric signals-based control [70]. The control techniques of the former studies used are (1) hybrid position/force control by using a gauge pressure sensor [48] and applying the rotary and linear encoder [47] to configure the support moment; (2) the force control [72,73], to apply precise force or torque to the device; (3) bounded control [45,46] that increases safety and prevents actuator saturation; (4) impedance control [40,58,61,67] which maps the desired trajectory and the stiffness; (5) position control [55,74,75], tracking normal patterns of walking and operating the device; (6) bioelectric signals-based control [3] that merges the relation between muscle activity and human movement; (7) on-off control [71] that generates and degenerates support in a specific condition.
From human gait cycles, the knee angle, an angle between the thigh leg and shin leg where it is 0 when two sections are parallel, is between 0 and around 70 degrees [57], so the range of motion of the device should smoothly operate between these degrees. The knee joint acts as a pivot joint between the thigh leg and shin leg, while the quadriceps muscles operate across it [76]. Dynamic and static stability of the knee joint can be controlled by muscles, tendons, and ligaments [77]. In addition, the joint can be assumed as a four-bar linkage [1,56,78] with a moving center of rotation point. The joint is stable because the muscles and ligaments [2,3] act as a dampener. There are two basic phases in a normal human gait cycle: stance phase and swing phase, with the stance phase being further divided into the weight acceptance phase and terminal stance phase [70], as shown in Figure 1 (modified from [70]). The weight acceptance phase occurs when a foot begins to lie on the ground and sends body weight to the ground for balance. This phase ends when the foot fully presses the ground. The terminal stance phase starts when the foot begins to kick the ground to continue walking. The swing phase occurs after the foot has been propelled off the ground. It is the phase in which a foot does not touch the ground and swings for preparing the next weight acceptance phase. Figure 2 shows the plots of human knee joint angle and moment per body mass during a gait cycle from modified raw data [57]. The maximum knee moment per body mass is around 0.67 Nm/kg. Note that the flexion moment is negative. Robotics 2023, 12, x FOR PEER REVIEW 3 of 21 A possibility of whether the stance and swing phase can be predicted by the angular velocity of the lower leg was presented by Grimmer et al. [80]. Attaching five inertial measurement units (IMUs) makes it possible to detect the stance phase while applying additional rule sets. The relative velocity between a thigh and shin leg was also suggested by Javanfar et al. [81]. The relative motion between the femur and tibia can be analyzed by the collision reactions of the knee's cartilage and bone. The results can suggest a design concept for a knee device.
The machine learning technique has been used for improving a knee device. Mokri et al. [82] can estimate a muscle force from the prediction of several machine learning methods, while the input is data from surface electromyography (sEMG) signals. This method can improve the performance of therapy and increase the sensitivity between the muscle model and the tendon stiffness. Machine learning was also applied for helping people with missing legs [83]. The study showed that the data from a series of foot pressure sensors can be used to predict the walking phase through the k−nearest neighbor (kNN) algorithm. Not only can healthy gait be detected by a machine learning model, but an abnormal gait can also be predicted. Chen et al. presented that their algorithm can predict the probability of elderly flat ground, which is helpful for the rehabilitation monitoring [84].
The control techniques usually require many sensors to control knee devices because of the complexity of movement, as the knee flexes and extends both when the foot touches and do not touch the ground. Nowadays, actuators combined with an encoder can give feedback on the motor's current angle and the angular velocity of the joint. For reducing the number of sensors in the device, this research proposes the machine learning and artificial stiffness control strategy (MLASCS) by using the knee angle and the knee angular velocity with machine learning and an artificial stiffness techniques for controlling the A possibility of whether the stance and swing phase can be predicted by the angular velocity of the lower leg was presented by Grimmer et al. [80]. Attaching five inertial measurement units (IMUs) makes it possible to detect the stance phase while applying additional rule sets. The relative velocity between a thigh and shin leg was also suggested by Javanfar et al. [81]. The relative motion between the femur and tibia can be analyzed by the collision reactions of the knee's cartilage and bone. The results can suggest a design concept for a knee device.
The machine learning technique has been used for improving a knee device. Mokri et al. [82] can estimate a muscle force from the prediction of several machine learning methods, while the input is data from surface electromyography (sEMG) signals. This method can improve the performance of therapy and increase the sensitivity between the muscle model and the tendon stiffness. Machine learning was also applied for helping people with missing legs [83]. The study showed that the data from a series of foot pressure sensors can be used to predict the walking phase through the k−nearest neighbor (kNN) algorithm. Not only can healthy gait be detected by a machine learning model, but an abnormal gait can also be predicted. Chen et al. presented that their algorithm can predict the probability of elderly flat ground, which is helpful for the rehabilitation monitoring [84].
The control techniques usually require many sensors to control knee devices because of the complexity of movement, as the knee flexes and extends both when the foot touches and do not touch the ground. Nowadays, actuators combined with an encoder can give feedback on the motor's current angle and the angular velocity of the joint. For reducing the number of sensors in the device, this research proposes the machine learning and artificial stiffness control strategy (MLASCS) by using the knee angle and the knee angular velocity with machine learning and an artificial stiffness techniques for controlling the A possibility of whether the stance and swing phase can be predicted by the angular velocity of the lower leg was presented by Grimmer et al. [80]. Attaching five inertial measurement units (IMUs) makes it possible to detect the stance phase while applying additional rule sets. The relative velocity between a thigh and shin leg was also suggested by Javanfar et al. [81]. The relative motion between the femur and tibia can be analyzed by the collision reactions of the knee's cartilage and bone. The results can suggest a design concept for a knee device.
The machine learning technique has been used for improving a knee device. Mokri et al. [82] can estimate a muscle force from the prediction of several machine learning methods, while the input is data from surface electromyography (sEMG) signals. This method can improve the performance of therapy and increase the sensitivity between the muscle model and the tendon stiffness. Machine learning was also applied for helping people with missing legs [83]. The study showed that the data from a series of foot pressure sensors can be used to predict the walking phase through the k−nearest neighbor (kNN) algorithm. Not only can healthy gait be detected by a machine learning model, but an abnormal gait can also be predicted. Chen et al. presented that their algorithm can predict the probability of elderly flat ground, which is helpful for the rehabilitation monitoring [84].
The control techniques usually require many sensors to control knee devices because of the complexity of movement, as the knee flexes and extends both when the foot touches and do not touch the ground. Nowadays, actuators combined with an encoder can give feedback on the motor's current angle and the angular velocity of the joint. For reducing the number of sensors in the device, this research proposes the machine learning and artificial stiffness control strategy (MLASCS) by using the knee angle and the knee angular velocity with machine learning and an artificial stiffness techniques for controlling the amount of supporting moment of the knee assistive device in a gait cycle. The machine learning model is introduced to classify the state of a gait cycle for mapping the amount of stiffness to support the required knee moment. This study explains how to create the MLASCS and validates the efficiency of this strategy by simulating the effort used when walking with and without MLASCS. The results of this study can indicate if machine learning can be applied for finding a state of gait, the amount of supporting knee moment, and if the MLASCS can be used for knee devices, knee robotic systems, and humanoid robots.
The paper is organized as follows. Section 2 describes how to collect and prepare data for calculations. Section 3 gives details on the creation of the MLASCS composed of machine learning and artificial stiffness control techniques. In Section 4, the simulation and validation of the MLASCS are shown. The results and discussion are displayed in Section 5. Finally, Section 6 concludes all the details of the study and discusses future work.

Knee Joint Data Collection of Walking Gait Cycle
Even though there is a lot of recorded knee joint data on a normal human gait cycle, there still might not be much knee data measured on Asian people which differs from data on Western people. Therefore, the data in walking gaits are measured in our research laboratory to make sure that the number of data points is large enough for creating a machine learning model.

Data Collection
The information on knee angle and moment are necessary to analyze and understand a human gait cycle for creating assistive knee motion devices. The knee moment can be determined by a ground reaction force (GRF) using inverse kinematics calculations. One effective way to determine knee movement and ground reaction force is from a motion capture sensor and force plate sensors. In the motion capture device, markers should be placed at the proper positions during measurement. According to the recommendations by Robertson et al. [85], there should be at least two positions in each segment, for example, in the lower leg the markers should be near the knee and the ankle so that the angular velocity can be determined. Therefore, the CG, the hip, the knee, the ankle, and the finger markers were attached at the positions shown in Figure 3. In addition, the average walking speed of all participants was approximately 1.5 m/s. amount of supporting moment of the knee assistive device in a gait cycle. The machine learning model is introduced to classify the state of a gait cycle for mapping the amount of stiffness to support the required knee moment. This study explains how to create the MLASCS and validates the efficiency of this strategy by simulating the effort used when walking with and without MLASCS. The results of this study can indicate if machine learning can be applied for finding a state of gait, the amount of supporting knee moment, and if the MLASCS can be used for knee devices, knee robotic systems, and humanoid robots. The paper is organized as follows. Section 2 describes how to collect and prepare data for calculations. Section 3 gives details on the creation of the MLASCS composed of machine learning and artificial stiffness control techniques. In Section 4, the simulation and validation of the MLASCS are shown. The results and discussion are displayed in Section 5. Finally, Section 6 concludes all the details of the study and discusses future work.

Knee Joint Data Collection of Walking Gait Cycle
Even though there is a lot of recorded knee joint data on a normal human gait cycle, there still might not be much knee data measured on Asian people which differs from data on Western people. Therefore, the data in walking gaits are measured in our research laboratory to make sure that the number of data points is large enough for creating a machine learning model.

Data Collection
The information on knee angle and moment are necessary to analyze and understand a human gait cycle for creating assistive knee motion devices. The knee moment can be determined by a ground reaction force (GRF) using inverse kinematics calculations. One effective way to determine knee movement and ground reaction force is from a motion capture sensor and force plate sensors. In the motion capture device, markers should be placed at the proper positions during measurement. According to the recommendations by Robertson et al. [85], there should be at least two positions in each segment, for example, in the lower leg the markers should be near the knee and the ankle so that the angular velocity can be determined. Therefore, the CG, the hip, the knee, the ankle, and the finger markers were attached at the positions shown in Figure 3. In addition, the average walking speed of all participants was approximately 1.5 m/s.  The CG marker is attached at around 0.412 of sample height (proximal) following the recommendation by Robertson et al. [85] to estimate the precise walking speed of the sample. The hip, the knee, the ankle, and the finger markers were attached to measure each 3D position, following the Qualisys Software Manual, for calculating knee and ankle angles. In this experiment, three participants were measured for nine trials in total. The participants are Thai adults whose average age is 23, whose height is 171-172 cm, and whose weight is 51.9-61.8 kg. The measurements also included two force plate sensors on the ground to measure the GRF. The experiment room has 16 marker detectors, 2 force plates, and 1 camera. The experiment room with markers attached to the participant is shown in Figure 4. The CG marker is attached at around 0.412 of sample height (proximal) following the recommendation by Robertson et al. [85] to estimate the precise walking speed of the sample. The hip, the knee, the ankle, and the finger markers were attached to measure each 3D position, following the Qualisys Software Manual, for calculating knee and ankle angles. In this experiment, three participants were measured for nine trials in total. The participants are Thai adults whose average age is 23, whose height is 171-172 cm, and whose weight is 51.9-61.8 kg. The measurements also included two force plate sensors on the ground to measure the GRF. The experiment room has 16 marker detectors, 2 force plates, and 1 camera. The experiment room with markers attached to the participant is shown in Figure 4.

Data Analyzing
The sampling frequency of the motion capture is around 240 Hz. MATLAB was used to resample the recorded data to have the same data points. The noise is also eliminated by MATLAB.

Kinematics of Knee
The raw data of the CG, the hip, the knee, the ankle, and the finger markers are represented in 3D positions in which the knee angles and ankle angles are determined. The slight variation in the y-axis data is negligible and, thus, only data in the X-Z plane is analyzed. Because all of the collected data are positions and angles, it is necessary to calculate velocity and acceleration for further calculations. The centered finite difference (CFD) method with an accuracy of order four was used to calculate velocity and acceleration. The regular CFD equation is as follows [86]: It can be calculated for more accurate prediction in the first derivatives for velocity, as follows [87]: and second derivatives for acceleration [87], as follows: where x is the time values, f(x) is the function, f'(x) is the first derivative function, f"(x) is the second derivative function, and h represents the small step time.

Data Analyzing
The sampling frequency of the motion capture is around 240 Hz. MATLAB was used to resample the recorded data to have the same data points. The noise is also eliminated by MATLAB.

Kinematics of Knee
The raw data of the CG, the hip, the knee, the ankle, and the finger markers are represented in 3D positions in which the knee angles and ankle angles are determined. The slight variation in the y-axis data is negligible and, thus, only data in the X-Z plane is analyzed. Because all of the collected data are positions and angles, it is necessary to calculate velocity and acceleration for further calculations. The centered finite difference (CFD) method with an accuracy of order four was used to calculate velocity and acceleration. The regular CFD equation is as follows [86]: It can be calculated for more accurate prediction in the first derivatives for velocity, as follows [87]: and second derivatives for acceleration [87], as follows: where x is the time values, f(x) is the function, f (x) is the first derivative function, f (x) is the second derivative function, and h represents the small step time.
It was found that the collected data on knee angle has some noise; therefore, all knee angle data required post-process signal processing before determining the knee angular velocity (knee omega). The average of the processed knee angles and knee omegas with the boundaries of all nine trial data are shown in Figure 5, whereas the starting position is when the heel touches the force plate.
Robotics 2023, 12, x FOR PEER REVIEW 6 of 21 It was found that the collected data on knee angle has some noise; therefore, all knee angle data required post-process signal processing before determining the knee angular velocity (knee omega). The average of the processed knee angles and knee omegas with the boundaries of all nine trial data are shown in Figure 5, whereas the starting position is when the heel touches the force plate.

Kinetics of Knee
The following is the process for calculating knee moment (Mknee) from the GRF. All equations are modified from Newton's 3rd Law (Equations (4) and (5)) for planar motion where the free body diagrams of the lower leg and the foot are shown in Figure 6. There are two steps in this calculation. The first step is the calculation of both the x and z directions of the ankle reaction force (Fx, ankle and Fz, ankle) and the ankle moment (Mankle) from the x and the z directions of the GRF (GRFx and GRFz) shown in Equations (6)- (8). Equations (4) and (5) are as follows: where ∑ F represents the summation of all the forces that act on the body, m is the mass of the body, and a is the acceleration of the body. ∑ M is the summation of all action moments exerted on the body around a specific point (G), the I is the moment of inertia of the body around the point, and the α is the angular acceleration of the body around the point. From the free body diagram of the lower leg and foot shown in Figure 6, the forces on the ankles can be calculated by the following equations: F z,ankle =GRF z -W foot -m foot a z,foot (7)

Kinetics of Knee
The following is the process for calculating knee moment (M knee ) from the GRF. All equations are modified from Newton's 3rd Law (Equations (4) and (5)) for planar motion where the free body diagrams of the lower leg and the foot are shown in Figure 6. There are two steps in this calculation. The first step is the calculation of both the x and z directions of the ankle reaction force (F x, ankle and F z, ankle ) and the ankle moment (M ankle ) from the x and the z directions of the GRF (GRF x and GRF z ) shown in Equations (6)- (8). Equations (4) and (5) are as follows: where ∑ F represents the summation of all the forces that act on the body, m is the mass of the body, and a is the acceleration of the body. ∑ M is the summation of all action moments exerted on the body around a specific point (G), the I is the moment of inertia of the body around the point, and the α is the angular acceleration of the body around the point. From the free body diagram of the lower leg and foot shown in Figure 6, the forces on the ankles can be calculated by the following equations: The moment around the ankle is as follows: where GRF x and GRF z are the ground reaction force in the x and z directions, respectively.
The R x , GRF and R z, GRF are the lever arm distance between the instantaneous center of rotation of the ankle (ICR ankle ) and GRF x and GRF z , respectively. Note that, the position data of the ankle marker, placed at the apex of the lateral malleolus, was used as the position of the ICR ankle in this calculation. The mass m foot is the estimated mass of the foot, which is approximately 0.0145 of body mass (m body ) [85]. Here, a x, foot and a z, foot are the accelerations at the foot's center of mass in the x and z-directions, W foot is the weight of the foot, R cm, ankle is the lever arm distance between the ICR ankle and W foot , I ankle is the moment of inertia around ICR ankle of which the radius of gyration is approximately 0.690 of the foot length [85], and α ankle is the angular acceleration of the ankle. All positions of the variables are shown in Figure 6, where F x, knee and F z, knee are the knee reaction forces in the x and z direction, respectively. Hence, the moment of the knee M knee can be calculated from the F x, ankle , F z, ankle and M ankle via the following equation: where W leg is the weight of the lower leg, which is approximately 0.0465 of body mass [85], R cm, knee is the level arm distance between the instantaneous center of rotation of the knee ICR knee and W leg , R x, leg and R z, leg are the lever arm distances between ICR knee and F x, ankle and F z, ankle , respectively, I knee is the moment of inertia around ICR knee of which the radius of gyration is approximately 0.528 of the lower leg length [85], and α knee is the angular acceleration of the knee. The moment around the ankle is as follows: where GRF x and GRF z are the ground reaction force in the x and z directions, respectively. The Rx, GRF and Rz, GRF are the lever arm distance between the instantaneous center of rotation of the ankle (ICRankle) and GRFx and GRFz, respectively. Note that, the position data of the ankle marker, placed at the apex of the lateral malleolus, was used as the position of the ICRankle in this calculation. The mass mfoot is the estimated mass of the foot, which is approximately 0.0145 of body mass (mbody) [85]. Here, ax, foot and az, foot are the accelerations at the foot's center of mass in the x and z-directions, Wfoot is the weight of the foot, Rcm, ankle is the lever arm distance between the ICRankle and Wfoot, Iankle is the moment of inertia around ICRankle of which the radius of gyration is approximately 0.690 of the foot length [85], and αankle is the angular acceleration of the ankle. All positions of the variables are shown in Figure 6, where Fx, knee and Fz, knee are the knee reaction forces in the x and z direction, respectively. Hence, the moment of the knee Mknee can be calculated from the Fx, ankle, Fz, ankle and Mankle via the following equation: The knee moment per body mass (MPB knee ) during a gait cycle of all trials can be determined from the knee moment (M knee ) and the body mass (m body ), as follows: The average and the boundaries of the calculated knee moment per body mass are shown in Figure 7, whereas the knee extension moment is positive, and the knee flexion moment is negative. Even though the results are slightly different from the previous study by Winter [57], the trends of all knee moments are quite similar. The difference in the results might be from differences in step lengths, foot shapes, stride shapes, etc. Even the same person can have different knee moment paths in each step, so it may be normal if different people have different knee moments.

Machine Learning and Artificial Stiffness Control Strategy (MLASCS)
The machine learning and artificial stiffness control strategy (MLASCS) is proposed as an alternative strategy to control a knee assistive device in a gait cycle. The advantage of this strategy is that only the knee angle and the knee angular velocity (knee omega) are required to determine the state of a gait cycle and the amount of support moment provided by the device. In order to make sure that the device does not cause any unwanted injury to the wearer, the MLASCS control system should be combined with a possibility checking function for increasing the accuracy of the state predicted, and various stiffness functions for increasing the suitability of the supporting moment. Furthermore, the artificial stiffness with a goal position can generate a moment of direct command. Artificial stiffness is a function that can predict the amount of stiffness required for supporting gait by the knee angle and the state of gait.

Classification and Training for Machine Learning Model
In a gait cycle, there are two main phases, which are the stance phase and the swing phase, and one knee angle can be in both the swing and stance phases. Therefore, it is necessary to create a machine learning model to classify the walking stage for predicting the walking phase to determine proper knee moment support at any position of a gait cycle.

Classification
As stated above, the position of a gait cycle and a state of walking cannot be determined from just a knee angle, and the second variable that can be used to classify the state is knee omega. As shown in Figure 8, all nine trial data were calculated by Equation (2), post-processed, and plotted to see the relationship between knee angle and knee omega. The inner loop and outer loop cannot be mapped to the swing and stance phases. Therefore, a new set of states in a gait cycle should be invented for further control in this system.

Machine Learning and Artificial Stiffness Control Strategy (MLASCS)
The machine learning and artificial stiffness control strategy (MLASCS) is proposed as an alternative strategy to control a knee assistive device in a gait cycle. The advantage of this strategy is that only the knee angle and the knee angular velocity (knee omega) are required to determine the state of a gait cycle and the amount of support moment provided by the device. In order to make sure that the device does not cause any unwanted injury to the wearer, the MLASCS control system should be combined with a possibility checking function for increasing the accuracy of the state predicted, and various stiffness functions for increasing the suitability of the supporting moment. Furthermore, the artificial stiffness with a goal position can generate a moment of direct command. Artificial stiffness is a function that can predict the amount of stiffness required for supporting gait by the knee angle and the state of gait.

Classification and Training for Machine Learning Model
In a gait cycle, there are two main phases, which are the stance phase and the swing phase, and one knee angle can be in both the swing and stance phases. Therefore, it is necessary to create a machine learning model to classify the walking stage for predicting the walking phase to determine proper knee moment support at any position of a gait cycle.

Classification
As stated above, the position of a gait cycle and a state of walking cannot be determined from just a knee angle, and the second variable that can be used to classify the state is knee omega. As shown in Figure 8, all nine trial data were calculated by Equation (2), post-processed, and plotted to see the relationship between knee angle and knee omega. The inner loop and outer loop cannot be mapped to the swing and stance phases. Therefore, a new set of states in a gait cycle should be invented for further control in this system.
As observed from a gait cycle, the plot could be separated into four states by the local minimum and maximum points in a knee angle for easy classification in a training process. These are initial place, final place, initial lift, and final lift states, where each state position is also shown in Figure 8 and can be mapped to a gait cycle as shown in Figure 9. The initial place starts when the knee is fully extended before the heel touches the ground (omega is more than zero within the inner loop). Then, the final place begins after the knee extends from flexing because of the body weight while being placed on the ground (omega is less than zero within the inner loop). After the foot kicks the ground and starts flexing within the stance phase, the initial lift starts (omega is more than zero). Finally, the final lift is the state when the knee extends for a heel strike in the next gait cycle (omega is less than zero).
Robotics 2023, 12, x FOR PEER REVIEW 9 of 21 Figure 8. The plot of the nine trial knee angle from post-processed recorded data and knee omega from post-processed and calculated recorded data by Equation (2); the plot can be separated into initial place, final place, initial lift, and final lift states.
As observed from a gait cycle, the plot could be separated into four states by the local minimum and maximum points in a knee angle for easy classification in a training process. These are initial place, final place, initial lift, and final lift states, where each state position is also shown in Figure 8 and can be mapped to a gait cycle as shown in Figure 9. The initial place starts when the knee is fully extended before the heel touches the ground (omega is more than zero within the inner loop). Then, the final place begins after the knee extends from flexing because of the body weight while being placed on the ground (omega is less than zero within the inner loop). After the foot kicks the ground and starts flexing within the stance phase, the initial lift starts (omega is more than zero). Finally, the final lift is the state when the knee extends for a heel strike in the next gait cycle (omega is less than zero).    (2); the plot can be separated into initial place, final place, initial lift, and final lift states.
As observed from a gait cycle, the plot could be separated into four states by the local minimum and maximum points in a knee angle for easy classification in a training process. These are initial place, final place, initial lift, and final lift states, where each state position is also shown in Figure 8 and can be mapped to a gait cycle as shown in Figure 9. The initial place starts when the knee is fully extended before the heel touches the ground (omega is more than zero within the inner loop). Then, the final place begins after the knee extends from flexing because of the body weight while being placed on the ground (omega is less than zero within the inner loop). After the foot kicks the ground and starts flexing within the stance phase, the initial lift starts (omega is more than zero). Finally, the final lift is the state when the knee extends for a heel strike in the next gait cycle (omega is less than zero).  In the initial and final place states, the knee angle does not exceed 25 degrees by observation from the gait cycle. The knee omega in the initial place state should be positive and negative for the final place state. The knee omegas of the initial and final lift states have the same characteristics in the initial and final place, but the knee angle can be up to 70 degrees following the recorded data.

Training
After defining the state of all training data, the classification learner of the MATLAB program was used to create a machine learning model. The benefit of a machine learning technique is that the model can classify precisely when there are a lot of training data. In that case, if the model can predict the state correctly with a difference in gait speed, the model is truly helpful. However, the model should predict correctly at least in a specific gait speed before testing with different gait speed training data. This paper focus on data with a gait speed of around 1.5 m/s. The training data was trained with many types of classifiers such as decision trees (accuracy: 80.0-92.5%), discriminant analysis (accuracy: 76.6-77.1%), naïve Bayes classifiers (accuracy: 77.6-81.5%), support vector machines (accuracy: 84.8%-93.7%), and nearest neighbor classifiers (accuracy: 78.8-95.0%). The best accuracy model type of mentioned classifier is the k-nearest neighbor (KNN) with the setting for training shown in Table 1, of which the accuracy is around 95.0%. After comparing the predicted state with the testing data, it is found that most of the incorrect predictions are at the intersection point between the initial place and initial lift (see Figure 8) where the exerted moments are much different, so it might be dangerous operating the knee device with this model. Thus, the continuity of state checking (CoSC) is presented to improve prediction accuracy. The CoSC requires the last and current predicted state to confirm the correctness of the prediction. Because walking is a continuous loop posture, all states go in the following order: the initial place, final place, initial lift, final lift, and then it starts a new loop with the initial place state. In order to prevent misclassifying between the initial place and the initial lift, the CoSC was applied to confirm that the initial lift state always follows the initial lift or final place, and the initial place state chases the initial place and final lift only. After predicting the sample data with the machine learning model with the CoSC, the accuracy increased to 99.9%, as seen in the validation confusion matrix of the machine learning model in Figure 10. However, the limitation of this machine learning model is that the model was calculated from the gait data with a gait speed of around 1.5 m/s. The accuracy may decrease if the model were to be used to predict data from another gait speed. Nonetheless, the state of any gait cycle still circulates as the initial place, final place, initial lift, and final lift. Therefore, the CoSC can lead the prediction state result state to follow the loop of states in a gait cycle. Another limitation is the processing time; the fastest prediction speed is around 168 observations per second. Note that the prediction speed can be changed depending on the computer and its processor.

Artificial Stiffness Control
An artificial stiffness control is an alternative method to support knee moments during a gait cycle. The idea comes from an observation of a torsion spring that can generate a return moment if the spring moves from rest. Therefore, if a controllable actuator is commanded with the desired position, the artificial rest position, and the proportional gain, it can act like a torsion spring with the desired stiffness. Compared to a direct torque-applied method, this method may be more friendly to the user because a supporting moment acts like an elastic spring. If it approaches the desired position, the generated moment should drop and eventually stop as it reaches the desired position.

Artificial Stiffness Control
An artificial stiffness control is an alternative method to support knee moments during a gait cycle. The idea comes from an observation of a torsion spring that can generate a return moment if the spring moves from rest. Therefore, if a controllable actuator is commanded with the desired position, the artificial rest position, and the proportional gain, it can act like a torsion spring with the desired stiffness. Compared to a direct torqueapplied method, this method may be more friendly to the user because a supporting moment acts like an elastic spring. If it approaches the desired position, the generated moment should drop and eventually stop as it reaches the desired position.

Instantaneous Artificial Stiffness (IAS)
An instantaneous artificial stiffness is estimated from a knee moment (Mknee) and an angle deflection, a constant determinable number that deflects from the knee angle. If the determined deflection angle is low, the IAS will be high, and vice versa, as seen in the following equation of knee moment: Thus, in this case, the deflection was set to 10 degrees because the instantaneous artificial stiffness is not large, and there is enough deflection for commanding an actuator to operate. In general, MPBknee was used instead of the Mknee to estimate an instantaneous artificial stiffness per body mass (IASPB), as seen in the following Equation (12), where i represents the knee angle:

Artificial Stiffness Control Equations
Because the gait cycles of different persons may not be the same, it is better to find the equations to estimate the instantaneous artificial stiffness per body mass (IASPB) in a gait cycle, so the equations can be used commonly. The average knee moment per body mass (AMPBknee), calculated from the average of all MPBknee data, was used to obtain IASPB equations in each state by the polyfit function in MATLAB, as shown in Equations (13)- (16). The IASPBIP, IASPBFP, IASPBIL, and IASPBFL are the functions of IASPB in the

Instantaneous Artificial Stiffness (IAS)
An instantaneous artificial stiffness is estimated from a knee moment (M knee ) and an angle deflection, a constant determinable number that deflects from the knee angle. If the determined deflection angle is low, the IAS will be high, and vice versa, as seen in the following equation of knee moment: Thus, in this case, the deflection was set to 10 degrees because the instantaneous artificial stiffness is not large, and there is enough deflection for commanding an actuator to operate. In general, MPB knee was used instead of the M knee to estimate an instantaneous artificial stiffness per body mass (IASPB), as seen in the following Equation (12), where i represents the knee angle:

Artificial Stiffness Control Equations
Because the gait cycles of different persons may not be the same, it is better to find the equations to estimate the instantaneous artificial stiffness per body mass (IASPB) in a gait cycle, so the equations can be used commonly. The average knee moment per body mass (AMPB knee ), calculated from the average of all MPB knee data, was used to obtain IASPB equations in each state by the polyfit function in MATLAB, as shown in Equations (13)- (16). The IASPB IP , IASPB FP , IASPB IL , and IASPB FL are the functions of IASPB in the initial place, final place, initial lift, and final lift state, respectively, where a is the knee angle. Figure 11 shows plots of the IASPB path on knee angle in all trials and the estimated value from the equations in each state, where the positive value means the extension direction and the negative value is the flexion direction.
IASPB IP (a) = 0.0073a 2 + 0.0391a + 0.0179 (13) IASPB FP (a) = 0.0023a 2 + 0.0237a + 0.0303 IASPB IL (a) = −0.002a 5 + 0.0057a 4 + 0.0067a 3 − 0.026a 2 + 0.0019a + 0.0279 (15) IASPB FL (a) = − 0.0028a 2 + 0.0111a − 0.003 (16) IASPBIP (a) = 0.0073a 2 + 0.0391a + 0.0179 (13) IASPBFP (a) = 0.0023a 2 + 0.0237a + 0.0303 (14) IASPBIL (a) = −0.002a 5 + 0.0057a 4 + 0.0067a 3 − 0.026a 2 + 0.0019a + 0.0279 (15) IASPBFL (a) = − 0.0028a 2 + 0.0111a − 0.003 (16) The concept of artificial stiffness control combined with machine learning is shown in Figure 12. The current knee angle (θ) and the current knee omega (ω) measured from the encoder were used to predict the current state of a gait cycle by the machine learning model. After that, the current state and θ were used to calculate the current IASPB. The current IASPB was then multiplied by the body mass and the mass of a sample to obtain an instantaneous artificial stiffness (IAS). The actuator required the IAS and the desired position (θ desired ) to generate the moment for supporting the knee. The θ desired is set to be 10 degrees away from the θ. Finally, the IAS and θ desired were used to command the actuator.  The concept of artificial stiffness control combined with machine learning is shown in Figure 12. The current knee angle (θ) and the current knee omega (ω) measured from the encoder were used to predict the current state of a gait cycle by the machine learning model. After that, the current state and θ were used to calculate the current IASPB. The current IASPB was then multiplied by the body mass and the mass of a sample to obtain an instantaneous artificial stiffness (IAS). The actuator required the IAS and the desired position (θ desired ) to generate the moment for supporting the knee. The θ desired is set to be 10 degrees away from the θ. Finally, the IAS and θ desired were used to command the actuator. IASPBFP (a) = 0.0023a 2 + 0.0237a + 0.0303 (14) IASPBIL (a) = −0.002a 5 + 0.0057a 4 + 0.0067a 3 − 0.026a 2 + 0.0019a + 0.0279 (15) IASPBFL (a) = − 0.0028a 2 + 0.0111a − 0.003 (16) The concept of artificial stiffness control combined with machine learning is shown in Figure 12. The current knee angle (θ) and the current knee omega (ω) measured from the encoder were used to predict the current state of a gait cycle by the machine learning model. After that, the current state and θ were used to calculate the current IASPB. The current IASPB was then multiplied by the body mass and the mass of a sample to obtain an instantaneous artificial stiffness (IAS). The actuator required the IAS and the desired position (θ desired ) to generate the moment for supporting the knee. The θ desired is set to be 10 degrees away from the θ. Finally, the IAS and θ desired were used to command the actuator.

Simulation and Validation
This part shows the simulation method to validate the MLASCS concept and also determines the effort over a gait cycle (modified from [31]) for comparing the walking efficiency. The data for testing was from the average knee angle and knee omega of the nine trial data recorded. In the simulation, the supporting moment, which is the moment generated by the actuator for assisting the walking, was estimated by using instantaneous artificial stiffness (IAS) equations. The simulation path was calculated as shown in Figure 12. The sample knee angle and omega predicted the state of gait by the machine learning model. Then, the predicted state and knee angle mapped the amount of IASPB using Equations (13)- (16). Finally, the IASPB was multiplied by the sample mass and predicted the amount of supporting moment by multiplying the IAS with the angle deflection. The validation is carried out by comparing the amount of effort over a gait cycle when applying supporting moments to the amount of effort without the support.

Supporting Moment Simulation
The simulation settings were chosen to have the test as close to the real system. The knee angle (θ) and the knee omega (ω) of the sample were imported one set at a time. Then, this set was used to predict the state and determine the IAS and θ desired . The IAS from the IASPB equations can be either positive or negative, but stiffness in the negative has no meaning. In the case that the IAS is negative, it will be change to positive, and the θ desired will be negative instead. The IAS, θ, and θ desired can be used to estimate the supporting moment (M s ) with an adjustable percentage of support (n), between 0-1, by the following equation: Furthermore, M s was used to calculate the remaining knee moment (M r ), i.e., the moment that is still required for walking after being supported by the device, via the following equation: After simulating with many sets of gait data, it is found that M s is frequently higher than the exerted moment. As a result, the percentage of support should be reduced. After optimizing the percentage of support to prevent over-assisting moments in all trial data, n should be less than 70% or 0.7. Consequently, all M knee data were compared to the average and boundary of M knee when the n is 0.7, as seen in Figure 13.
model. Then, the predicted state and knee angle mapped the amount of IASPB using Equations (13)- (16). Finally, the IASPB was multiplied by the sample mass and predicted the amount of supporting moment by multiplying the IAS with the angle deflection. The validation is carried out by comparing the amount of effort over a gait cycle when applying supporting moments to the amount of effort without the support.

Supporting Moment Simulation
The simulation settings were chosen to have the test as close to the real system. The knee angle (θ) and the knee omega (ω) of the sample were imported one set at a time. Then, this set was used to predict the state and determine the IAS and θ desired . The IAS from the IASPB equations can be either positive or negative, but stiffness in the negative has no meaning. In the case that the IAS is negative, it will be change to positive, and the θ desired will be negative instead. The IAS, θ, and θ desired can be used to estimate the supporting moment (Ms) with an adjustable percentage of support (n), between 0-1, by the following equation: Furthermore, Ms was used to calculate the remaining knee moment (Mr), i.e., the moment that is still required for walking after being supported by the device, via the following equation: After simulating with many sets of gait data, it is found that Ms is frequently higher than the exerted moment. As a result, the percentage of support should be reduced. After optimizing the percentage of support to prevent over-assisting moments in all trial data, n should be less than 70% or 0.7. Consequently, all Mknee data were compared to the average and boundary of Mknee when the n is 0.7, as seen in Figure 13. Figure 13. Plots of the average and boundary of knee moment (M knee ) and remaining knee moment (M r ), i.e., the moment that is still required for walking after being supported by the device when the percentage of support (n) is 0.7.

Effort over a Gait Cycle
An effort over a gait cycle can be used to validate and examine the difference of effort between the sample path and the resulting path obtained from the effort over time presented by Chaichaowarat et al. [31]. The effort over a gait cycle was divided into two parts, namely the extension effort (EE) and the flexion effort (FE). The EE and the FE were determined by integrating the extension moment (EM), i.e., the moment in extension direction, and the flexion moment (FM), i.e., the moment in flexion direction, over a percent of gait (PoG), as in Equations (19) and (20), respectively. Then, the summation of EE and FE is the total effort (TE), as in Equation (21), which is used for comparing the efficiency of the MLASCS. The efforts of each trial, calculated from the measured knee moment, and their remaining efforts, determined from the remaining moments with assistance from the device, are shown in Figure 14. 21) between the sample path and the resulting path obtained from the effort over time presented by Chaichaowarat et al. [31]. The effort over a gait cycle was divided into two parts, namely the extension effort (EE) and the flexion effort (FE). The EE and the FE were determined by integrating the extension moment (EM), i.e., the moment in extension direction, and the flexion moment (FM), i.e., the moment in flexion direction, over a percent of gait (PoG), as in Equations (19) and (20), respectively. Then, the summation of EE and FE is the total effort (TE), as in Equation (21), which is used for comparing the efficiency of the MLASCS. The efforts of each trial, calculated from the measured knee moment, and their remaining efforts, determined from the remaining moments with assistance from the device, are shown in Figure 14.

Results and Discussion
Knee assistive devices need knee data to control the device correctly without any harm to the user. The primary information for controlling a knee device is the knee angle and the knee moment. For controlling the walking gait, the secondary set of data required is the phase of gait, as each phase needs a different amount of support. Therefore, the machine learning and artificial stiffness control strategy (MLASCS) was applied to classify the phase of gait: initial place, final place, initial lift, and final lift state. After that, the predicted state and knee angle was used to estimate the amount of support by the instantaneous artificial stiffness per body mass (IASPB) equations mentioned in the above section. Figure 14. Comparison of the effort over a gait cycle from recorded walking data and remaining effort over a gait cycle in each trial. Note that the numbers shown at the top of the bars are the total effort of each bar.

Results and Discussion
Knee assistive devices need knee data to control the device correctly without any harm to the user. The primary information for controlling a knee device is the knee angle and the knee moment. For controlling the walking gait, the secondary set of data required is the phase of gait, as each phase needs a different amount of support. Therefore, the machine learning and artificial stiffness control strategy (MLASCS) was applied to classify the phase of gait: initial place, final place, initial lift, and final lift state. After that, the predicted state and knee angle was used to estimate the amount of support by the instantaneous artificial stiffness per body mass (IASPB) equations mentioned in the above section.
The instantaneous artificial stiffness per body mass (IASPB) equations were separated into four equations, namely IASPB IP , IASPB FP , IASPB IL , and IASPB FL , which are the functions of IASPB in the initial place, final place, initial lift, and final lift state, respectively. Each IASPB function was calculated from the average knee moment per body mass (AMPB knee ) so that the supporting moment may exceed or be lower compared to the required knee moment for walking. The percentage of support (n) was invented to adjust the supporting moment. As a result, the n should be 0.7 so that the supporting moment does not exceed the required moment.
In the simulation section, the MLASCS was tested by using all recorded trial data and average data to validate the efficiency of the strategy by using the effort over a gait cycle, as shown in the previous section. The results show that the prediction of the machine learning model is working well. The model mostly predicts the current state correctly, and the IASPB equations can give an amount of stiffness for supporting the knee in each position which is mainly a bit lower than required for walking. The total effort of the recorded data was converted to 100% for easy comparison with their total effort after it was supported in each trial shown, as shown in Table 2.
The total remaining effort, i.e., the effort that is still required for walking after supporting in each trial, showed that this strategy assists knee moments while walking in every trial. The percentage of the remaining effort will change if the percentage of support (n) is adjusted. For example, if the n is too high, the supporting moment will exceed the moment required, so the effort will be larger than the required effort, but if the n is too low, the effort will be close to the required effort which means it does not support enough. As seen in Table 2, the extension effort was highly reduced by the strategy compared to the flexion. In some trials, this strategy reduced the flexion effort by less than 10% or even increased the effort. As a result, it caused an adverse effect on the user. Then, the n should be changed individually depending on the user. Note that if the n is too small, the supporting moment is minimal, and vice versa. After testing and validating the MLASCS, it seems that the strategy can be used in a knee-assistive device. The technique can predict the amount of supporting moments from the recorded gait data. The MLASCS speed is around 165 observers/s. In a single gait cycle while walking around 1.5 m/s, the time duration is around 1.1 s, so the MLASCS can handle gait data and estimate the amount of supporting moment. The results showed that the walking effort was reduced to 63.4% when the n was 0.7.

Conclusions
In a knee assistive device, a control algorithm is one of the most important parts. Depending on the controlling system, the device can operate smoothly or harm a user. This study aims to validate a new type of control strategy called the machine learning and artificial stiffness control strategy (MLASCS) for commanding the proper amount of support moment to assist while walking. The MLASCS is composed of a trained machine learning model and the instantaneous artificial stiffness per body mass (IASPB) equations. The trained model can classify the state of a gait cycle by using knee angle and omega. The accuracy of the modified machine learning model is around 99.9%. The IASPB equations require the knee angle and the state to map the amount of stiffness to support the knee moment. The support moment will change if the user adjusts the percentage of support (n), so the user can select the amount of assistance. After validating the MLASCS with nine trial data sets, the strategy can reduce the total effort over a gait cycle up to 63.4% when the n was 0.7. The extension effort was mainly reduced, so for those who want to combine this strategy with the knee assistive device, the posterior support device is recommended. The authors highly recommend a device that is designed for supporting extension direction instead of flexion direction because of the high extension moment required for walking. Moreover, the knee joint of a knee device might not align with the human knee joint, so the machine learning model should be retrained following the joint angle while walking. Because there are many variables in this article, Table 3 summarizes important variables in this paper for a better understanding.  Author Contributions: Conceptualization, K.P. and N.A.; methodology, K.P. and N.A.; software, K.P.; validation, K.P.; formal analysis, K.P.; investigation, K.P.; resources, K.P. and N.A.; data curation, K.P.; writing-original draft preparation, K.P.; writing-review and editing, N.A.; visualization, K.P.; supervision, N.A.; project administration, K.P. and N.A.; funding acquisition, K.P. and N.A. All authors have read and agreed to the published version of the manuscript.