I'm building a lower limb exoskeleton with active hip, knee and ankle joints. Each joint has a brushless dc motor coupled to a 120:1 gear and the output shaft of each gear is coupled to a single turn (~320 degrees) potentiometer via a toothed belt and pulley for position data. The output shaft of the gear is also connected to the exoskeleton frame so that it can rotate each joint. An Arduino Mega Outputs a pwm signal to a motor controller to control speed and direction. [image attached]
I can drive each motor separately and both of the motors together but I want to do everything I can to make sure the two joints stay in sync and move accurately to the correct positions. I have a list of 50 data points for each joint. Each data point is an angle at which a joint should be for every 2% of a stride. The first data point is the angle a joint should be at the start, the next data point is the angle the joint should be at 2% of the stride and the next data point at 4% of the stride and so on.
Currently I'm moving each motor to the start position and then moving to each subsequent position in order. I'm calculating the speed by taking the difference in the data points and dividing it by 1/50th of the walking speed and generating a pwm value. This is pretty stuttery. Sometimes the motor overshoots the position, sometimes one motor reaches its target position before the other and has to wait.
I've started to look into PID control and played with it a bit for a single joint. I could get fairly decent position accuracy with little to no overshoot but I'm not sure how to incorporate speed and, again, most importantly, keep the joints in sync.
Here is the code so far. I had to attach it because it's too long. There's some extra stuff in here to communicate with a processing sketch, some notes to myself and some things I used to mess around with PID control. Comments on how to tidy things up or make them more efficient are appreciated but I'd rather not get too off topic if possible.
megaCode.ino (18.3 KB)