Skip to content

Commit

Permalink
servo360 - try adding delay in calculated distance during acceleration
Browse files Browse the repository at this point in the history
…#149 (step 1)

Added as commented code (that does work).  Needs either tuning or extra conditions so that it doesn't introduce errors when slowing down to a stop.
  • Loading branch information
AndyLindsay committed Oct 16, 2017
1 parent 721d9ca commit 68fea9e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 5 deletions.
Binary file modified Learn/Simple Libraries/Motor/libservo360/cmm/libservo360.a
Binary file not shown.
39 changes: 38 additions & 1 deletion Learn/Simple Libraries/Motor/libservo360/servo360.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,48 @@ int servo360_pidV(int p)
int opMax = _fs[p].speedLimit;

_fs[p].speedMeasured = (_fs[p].angle - _fs[p].angleP) * 50;

if(abs(_fs[p].angleError) < S360_UNITS_ENCODER/2)
{



//
_fs[p].angleDeltaCalc = _fs[p].speedTarget / S360_CS_HZ;
_fs[p].angleCalc += _fs[p].angleDeltaCalc;
}
//



/*
// This could remedy the overshoot problem, but it seems to reduce
// drive_goto accuracy.
if(_fs[p].speedTarget == _fs[p].speedTargetP)
{
_fs[p].offset--;
if(_fs[p].offset < 0) _fs[p].offset = 0;
}
else
{
_fs[p].offset++;
if(_fs[p].offset > FB360_OFFSET_MAX) _fs[p].offset = FB360_OFFSET_MAX;
}
int idx = _fb360c.pulseCount % FB360_V_ARRAY;
_fs[p].vT[idx] = _fs[p].speedTarget;
idx -= _fs[p].offset;
if(idx < 0) idx += FB360_V_ARRAY;
_fs[p].speedTargetTemp = _fs[p].vT[_fs[p].offset];
_fs[p].angleDeltaCalc = _fs[p].speedTargetTemp / S360_CS_HZ;
_fs[p].angleCalc += _fs[p].angleDeltaCalc;
*/



}

_fs[p].angleError = _fs[p].angleCalc - _fs[p].angle;

Expand Down
14 changes: 13 additions & 1 deletion Learn/Simple Libraries/Motor/libservo360/servo360.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ typedef volatile struct servo360_s
volatile int speedOut;
volatile int pw;

// speed control system
// velocity control system
volatile int opPidV;
volatile int approachFlag;
volatile int ticksDiff;
Expand All @@ -314,6 +314,18 @@ typedef volatile struct servo360_s
volatile int stepDir;
volatile int lag;
volatile int accelerating;
volatile int speedTargetTemp;

/*
// This could remedy the overshoot problem, but it seems to reduce
// drive_goto accuracy.
#define FB360_OFFSET_MAX 5
#define FB360_V_ARRAY 8
volatile int vT[FB360_V_ARRAY];
volatile int offset;
*/

// position control system
volatile int Kp;
Expand Down
4 changes: 2 additions & 2 deletions Learn/Simple Libraries/Motor/libservo360/z_dev_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ void console()
fbt[p].pV, fbt[p].iV, fbt[p].dV,
fbt[p].drive, fbt[p].opV, fbt[p].opPidV);
*/
dprint(term, "spR: %d, spT: %d, spM: %d\r",
fbt[p].speedReq, fbt[p].speedTarget, fbt[p].speedMeasured);
dprint(term, "spR: %d, spT: %d, spTT: %d, spM: %d\r",
fbt[p].speedReq, fbt[p].speedTarget, _fs[p].speedTargetTemp, fbt[p].speedMeasured);
dprint(term, "aC: %d, aM: %d, aE: %d\r",
fbt[p].angleCalc, fbt[p].angle, fbt[p].angleError);
dprint(term, "pV: %d, iV: %d, dV: %d\r",
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.4.15
v1.4.16

0 comments on commit 68fea9e

Please sign in to comment.