ebc3142 0 Newbie Poster

I'll just start by giving some context to the problem I'm trying to solve. Simply put, I'm trying to code an Arduino to accelerate a DC motor at a user-specified acceleration (encoder counts/sample/sample)

Before I can apply a PID filter to correct the velocity, I need to determine the theoretical position at each sampling interval. For the moment, let's assume the sampling rate is 2048/fCLK.

Now, I imagine If the motor was required to maintain a constant velocity (such as 10 encoder counts per sample), one could increment a counter by 10 at each iteration of a loop to determine the theoretical position. But, what would be the most appropriate way to calculate the position with only the acceleration rate and sample interval as out variables?

I had thought about representing the acceleration trajectory as a line equation and determining the position with Pythagoras. i.e. plug time (x) into the equation to calculate y, etc.

Obviously, the limitation with this would be having to keep track of time. Surely there's a simpler way to do this.

I presume the order of complexity for this problem is n^2. So, does this suggest some sort of a nested loop?

Pseudo-code would be much appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.