04-20-2021 01:35 PM
Hi,
I have servo actuator PWM signals and motor PWM signals each generated on different timestamp (microseconds). Now, I need to upsample the servo PWM signals to match the timestamp of motor PWM signals.
servo_sample = 1985 rows x 2 columns (1st column-timestamp of servo in microseconds, 2 nd column-servo PWM values)
Motor_sample = 9192 rows x 1 column (timestamp of motors in microseconds )
I have attached the sample file for reference.
Kindly to Note: Upsampled servo PWM array (9192 rows x 2 columns (1st column - timestamp of motors, 2nd column- upsampled servo pwm values) must contain previous/nearest values (strictly no interpolations) by comparing the timestamp of motor and servo.
Thank you.
Solved! Go to Solution.
04-20-2021 02:19 PM
I assume you also have motor PWM values somewhere but chose not to include them in the attached spreadsheet?
And further assuming both measurements are using the *same* microsecond timer and that time will only increase (no rollover back to 0), this one's pretty easy.
Code is attached and input arrays are populated with the data you provided.
-Kevin P
04-21-2021 04:11 AM
It worked. Great Help. Thank You, Kelvin.
04-21-2021 07:21 AM
Just a small additional tip:
That simple code was fine for your particular dataset because *all* the motor microsec timestamps were *interior* to the range represented by the set of servo microsec.
In a more general case, you'd need to add some checks and corrections for such situations.
I also notice that I accidentally labeled the output as "servo pwm" instead of "motor pwm". Oops, but you probably caught and fixed that already.
-Kevin P
04-22-2021 06:44 AM
Oops, just reread what I wrote. Checks and corrections are needed for the more general case where some of the motor microsec timestamps may fall OUTSIDE the range in the set of servo microsec.
-Kevin P
04-27-2021 06:52 AM - edited 04-27-2021 06:58 AM
Hi Kelvin,
Your suggestions are noted. I appreciate your continuous update on this.
Actually your vi helped me to upsample the current servo pwm values (logged at time interval of approx 80 millisec) to the motor timestamp (logged at approx.20 millisec) with only 1% error. To cross check, I manually chose the timestamp which is almost same in both motor and servo, then at this timestamp, I checked the output of servo pWM from your vi and log file. there is difference of about 1%. This is because of less similar values of motor and servo time stamp. To correct this 1 % error, I converted the time stamp from microsec to secs from 0 to 205 and used your vi. This helped me to remove even this 1% error.
Thank you for your help.