misan / dcservo

Position control of DC motors
315 stars 113 forks source link

dcservo.ino assigns long to byte #26

Open DrStein99 opened 7 years ago

DrStein99 commented 7 years ago

The "example" assigns "POS" as a byte, yet - assigns the LONG encoder position to this BYTE array.... Not sure how this actually would work

byte pos[1000]; int p=0;
volatile long encoder0Pos = 0;
double input=0, output=0, setpoint=0;

pos[p]=encoder0Pos; 
misan commented 7 years ago

Thanks @DrStein99.

It does not look good, but the initial aim was to use this feature only for PID tuning, where the tool would create a step from 0 to 220 (so all the expected values there would be with the byte range).

But you are right that this feature won't work properly most of the time unless used under similar conditions.

Not using a larger data size was due to the scarcity of RAM memory on Arduino UNO, so for other platforms, data type might be changed to integer or even long for reducing or removing the limitation you pointed out.

I can see this is mentioned in the comments of PID tunning tool: https://github.com/misan/dcservo/blob/master/PIDtunningTool.pde#L15

int targetVal = 220; // use this to set the target value
//please note the warparound effect on th graph if using values > 255 as Arduino only recording 8 bits location values :-(
DrStein99 commented 7 years ago

There are at least a couple other hang ups in the example I had to correct.

After I replaced the ENCODER translation to use the Encoder library, it solved ALOT.