26 #if defined(__cplusplus) 31 #include "simpletools.h" 34 #ifdef _servo360_monitor_ 40 #ifndef DOXYGEN_SHOULD_SKIP_THIS 44 #ifndef S360_UNITS_FULL_CIRCLE 45 #define S360_UNITS_FULL_CIRCLE 360 49 #ifndef S360_MAX_SPEED 50 #define S360_MAX_SPEED 2 * 4096 59 #define S360_VM_CCW S360_VM 63 #define S360_VM_CW S360_VM 67 #define S360_VM_CCW S360_VM 71 #define S360_VM_CW S360_VM 75 #define S360_VB_CCW 200 79 #define S360_VB_CW -200 83 #ifndef S360_DUTY_CYCLE_MIN 84 #define S360_DUTY_CYCLE_MIN 290 87 #ifndef S360_DUTY_CYCLE_MAX 88 #define S360_DUTY_CYCLE_MAX 9710 93 #define S360_CCW_POS 1 97 #define S360_CCW_NEG -1 105 #ifndef S360_POSITION 106 #define S360_POSITION 2 114 #define S360_MONITOR 4 117 #ifndef S360_FREQ_CTRL_SIG 118 #define S360_FREQ_CTRL_SIG 50 121 #ifndef S360_DEVS_MAX 122 #define S360_DEVS_MAX 4 127 #ifndef S360_RAMP_STEP 128 #define S360_RAMP_STEP 72 * 4096 / 360 142 #define S360_ENC_RES 4096 156 #define S360_KPA 12000 164 #define S360_KDA 6000 167 #ifndef S360_POS_INTGRL_MAX 168 #define S360_POS_INTGRL_MAX 600 171 #ifndef S360_SCALE_DEN_A 172 #define S360_SCALE_DEN_A 1000 195 #ifndef S360_VEL_INTGRL_MAX 196 #define S360_VEL_INTGRL_MAX 0 199 #ifndef S360_SCALE_DEN_V 200 #define S360_SCALE_DEN_V 1000 204 #ifndef S360_PW_CENTER 205 #define S360_PW_CENTER 15000 209 #define S360_CS_HZ 50 212 #ifndef S360_UNITS_ENCODER 213 #define S360_UNITS_ENCODER 4096 216 #ifndef S360_UNITS_REV 217 #define S360_UNITS_REV 360 221 #ifndef S360_SETTING_KPV 222 #define S360_SETTING_KPV 1 225 #ifndef S360_SETTING_KIV 226 #define S360_SETTING_KIV 2 229 #ifndef S360_SETTING_KDV 230 #define S360_SETTING_KDV 3 233 #ifndef S360_SETTING_IV_MAX 234 #define S360_SETTING_IV_MAX 4 237 #ifndef S360_SETTING_KPA 238 #define S360_SETTING_KPA 5 241 #ifndef S360_SETTING_KIA 242 #define S360_SETTING_KIA 6 245 #ifndef S360_SETTING_KDA 246 #define S360_SETTING_KDA 7 249 #ifndef S360_SETTING_IA_MAX 250 #define S360_SETTING_IA_MAX 8 253 #ifndef S360_SETTING_VB_CCW 254 #define S360_SETTING_VB_CCW 9 257 #ifndef S360_SETTING_VB_CW 258 #define S360_SETTING_VB_CW 10 261 #ifndef S360_SETTING_VM_CCW 262 #define S360_SETTING_VM_CCW 11 265 #ifndef S360_SETTING_VM_CW 266 #define S360_SETTING_VM_CW 12 272 #define S360_A_MAX 524287 276 #ifndef S360_SCALE_DEN_COUPLE 277 #define S360_SCALE_DEN_COUPLE 1000 280 #ifndef S360_SCALE_COUPLE 281 #define S360_SCALE_COUPLE 2000 286 #define S360_LATENCY 3 291 #define S360_PWMAX 2400 295 #define S360_PWMIN -2400 355 typedef volatile struct servo360_cog_s
358 volatile int lock360;
360 volatile int t360slice;
361 volatile int fbSlice;
362 volatile int spSlice;
363 volatile int devCount;
364 volatile int pulseCount;
365 volatile int cntPrev;
367 volatile int dt360a[2];
370 extern volatile servo360_cog_t _fb360c;
374 typedef volatile struct servo360_s
377 volatile int pinCtrl;
379 volatile int angleSign;
380 volatile int rampStep;
381 volatile int speedLimit;
382 volatile int feedback;
383 volatile int angleMax;
384 volatile int angleMin;
385 volatile int unitsRev;
387 volatile int coupleScale;
397 volatile int speedReq;
400 volatile int dc, dcp;
401 volatile int theta, thetaP;
403 volatile int angleFixed, angleFixedP;
404 volatile int angle, angleP, pvOffset;
409 volatile int speedOut;
414 volatile int approachFlag;
415 volatile int ticksDiff;
416 volatile int ticksGuard;
417 volatile int angleCalc;
418 volatile int angleDeltaCalc;
419 volatile int angleError;
420 volatile int erDist, erDistP;
421 volatile int speedTarget;
422 volatile int speedTargetP;
423 volatile int integralV;
424 volatile int derivativeV;
431 volatile int pV, iV, dV;
432 volatile int speedMeasured;
434 volatile int stepDir;
436 volatile int accelerating;
437 volatile int speedTargetTemp;
454 volatile int er, erP;
455 volatile int sp, integral, derivative;
456 volatile int op, iMax, iMin;
457 volatile int p, i, d;
460 volatile int angleTarget;
464 extern volatile servo360_t _fs[S360_DEVS_MAX];
467 #ifdef _servo360_monitor_ 469 extern volatile int suppressFbDisplay;
474 #endif // DOXYGEN_SHOULD_SKIP_THIS 1074 #ifndef DOXYGEN_SHOULD_SKIP_THIS 1079 void servo360_run(
void);
1080 void servo360_end();
1081 void servo360_setup(
void);
1082 void servo360_mainLoop();
1083 void servo360_outputSelector(
int p);
1085 void servo360_servoPulse(
int p,
int q);
1086 void servo360_waitServoCtrllEdgeNeg(
int p);
1087 int servo360_dutyCycle(
int p,
int scale);
1088 int servo360_crossing(
int current,
int previous,
int units);
1089 int servo360_getTheta(
int p);
1090 void servo360_checkAngle(
int p);
1091 void servo360_captureOffset(
int p);
1092 void servo360_setPositiveDirection(
int p,
int direction);
1096 int servo360_upsToPulseFromTransferFunction(
int unitsPerSec,
int p);
1097 void servo360_pulseControl(
int p,
int speedUps);
1099 void servo360_speedControl(
int p);
1100 int servo360_pidA(
int p);
1101 int servo360_pidV(
int p);
1103 int servo360_findServoIndex(
int pin);
1105 int servo360_unitsAngleToEncoder(
int value,
int unitsRev);
1106 int servo360_unitsEncoderToAngle(
int value,
int unitsRev);
1107 int servo360_checkDistanceRemaining(
int pin,
int speed,
int finalAngle);
1109 int servo360_setMaxSpeedEncoded(
int pin,
int speed);
1111 void servo360_monitorRun(
void);
1112 void servo360_monitorEnd(
void);
1114 int servo360_setTransferFunction(
int pin,
int constant,
int value);
1117 int servo360_getAngle12Bit(
int pin);
1118 int servo360_getAngleFixedOrigin(
int pin);
1126 #ifdef _servo360_monitor_ 1128 void servo360_monitor_start(
void);
1129 void servo360_monitor_stop();
1130 int terminal_checkForValue(fdserial *connection,
int *value);
1135 #endif // DOXYGEN_SHOULD_SKIP_THIS 1139 #if defined(__cplusplus) int servo360_getAngleCalc(int pin)
During servo360_speed maneuvers, the target position gets recalculated every 50th of a second...
Definition: servo360_getAngleCalc.c:17
int servo360_setUnitsFullCircle(int pin, int units)
Set the number of units in a full circle. By default, this value is 360. This function does not actu...
Definition: servo360_setUnitsFullCircle.c:17
int servo360_setTurns(int pin, int turns)
Change the number of turns that have elapsed since the application has started. Use this function to ...
Definition: servo360_setTurns.c:17
int servo360_getUnitsFullCircle(int pin)
Get the number of units in a full circle. By default, this value is 360, but it can be changed with s...
Definition: servo360_getUnitsFullCircle.c:17
int servo360_angle(int pin, int position)
Set an angle in degrees for servo to move to and hold. The default degree is 1/360th of a full circle...
Definition: servo360_angle.c:17
int servo360_enable(int pin, int state)
Enable or disable the control system signal.
Definition: servo360_enable.c:17
int servo360_getRampStep(int pin)
Get current acceleration setting in terms of degrees per second per 50th of a second. For a more straightforward implementation, use servo360_getAcceleration instead.
Definition: servo360_getRampStep.c:17
int servo360_setAngleCalc(int pin, int angle)
During servo360_speed maneuvers, the target position gets recalculated every 50th of a second...
Definition: servo360_setAngleCalc.c:17
int servo360_connect(int pinControl, int pinFeedback)
Initializes a connection to a Parallax Feedback 360 servo. The current position of the servo during t...
Definition: servo360_connect.c:19
int servo360_speed(int pin, int speed)
Set servo rotation speed in degrees per second. The default max values range from 720 degrees per sec...
Definition: servo360_speed.c:17
int servo360_getControlSys(int pin, int constant)
Check control system constant. See the servo360_setControlSys function for more info.
Definition: servo360_getControlSys.c:17
int servo360_setCoupleScale(int pinA, int pinB, int scale)
Change the scale factor in a pair of servos that were coupled with the servo360_couple call...
Definition: servo360_setCoupleScale.c:17
int servo360_getMaxSpeed(int pin)
Get the max speed setting.
Definition: servo360_getMaxSpeed.c:17
int servo360_getAngleLimits(int pin, int *ccwMax, int *cwMax)
Check the angle limits the servo is allowed to turn to during position control. These limits only aff...
Definition: servo360_getAngleLimits.c:17
int servo360_getAngleOffset(int pin)
Check the offset from the servo's mechanical 0-degree position. If servo360_setAngleOffset has not be...
Definition: servo360_getAngleOffset.c:17
int servo360_getTurns(int pin)
Get the number of times the output shaft has turned in a full circle since the application started (e...
Definition: servo360_getTurns.c:16
int servo360_setAngleLimits(int pin, int ccwMax, int cwMax)
Set the angle limits the servo is allowed to turn to during position control. These limits only affec...
Definition: servo360_setAngleLimits.c:17
int servo360_setControlSys(int pin, int constant, int value)
The servo360.h library is designed to use Proportional, Integral and Derivative (PID) control to main...
Definition: servo360_setControlSys.c:16
int servo360_getAcceleration(int pin)
Get current acceleration in terms of degrees per second squared.
Definition: servo360_getAcceleration.c:17
int servo360_setMaxSpeed(int pin, int speed)
Set the maximum servo speed in terms of degrees per second.
Definition: servo360_setMaxSpeed.c:17
int servo360_feedback(int pin, int state)
Enable or disable the feedback system. If the feedback system is disabled, the servo should only be c...
Definition: servo360_feedback.c:17
int servo360_setRampStep(int pin, int stepSize)
Set acceleration in terms of degrees per second per 50th of a second. For a more straightforward imp...
Definition: servo360_setRampStep.c:17
int servo360_setAcceleration(int pin, int unitsPerSecSquared)
Set acceleration in terms of degrees per second squared. The default is 3600 degrees per second squar...
Definition: servo360_setAcceleration.c:17
int servo360_goto(int pin, int position)
Go to a certain number of degrees from the current position. Positive values are counterclockwise, negative values are clockwise. This is a "set it and forget it" function that returns immediately after the maneuver has been initiated. The maneuver's progress can be monitored with servo360_getCsop and also with servo360_getAngle.
Definition: servo360_goto.c:16
int servo360_getSpeed(int pin)
Measure the current speed. For best results, take the average of multiple measurements.
Definition: servo360_getSpeed.c:17
int servo360_setAngleCtrlSpeedMax(int pin, int speed)
Set the maximum speed at which the servo is allowed to turn while adjusting to a new angle set point...
Definition: servo360_setAngleCtrlSpeedMax.c:17
int servo360_getAngle(int pin)
Get measured angle of servo in degree units.
Definition: servo360_getAngle.c:17
int servo360_getAngleCtrlSpeedMax(int pin)
Check the maximum speed at which the servo is allowed to turn while adjusting to a new angle set poin...
Definition: servo360_getAngleCtrlSpeedMax.c:17
int servo360_couple(int pinA, int pinB)
This function is used by the abdrive360 library to reduce the drive on a servo whose position is furt...
Definition: servo360_couple.c:17
int servo360_setAngleOffset(int pin, int angle)
Set the offset from the servo's mechanical 0 degree position. If this function is not called...
Definition: servo360_setAngleOffset.c:17
int servo360_getCsop(int pin)
Csop is an abbreviation for control system operation, which could be speed, position, or goto control. During a servo360_goto maneuver, this function will return S360_GOTO. When the maneuver has completed, it will return S360_POSITION.
Definition: servo360_getCsop.c:17
int servo360_stop(int pin)
Stop servo motion if it is turning. It is equivalent to a call to servo360_speed(pin, 0).
Definition: servo360_stop.c:17
int servo360_set(int pinControl, int time)
Use pulse width control to set servo speed without feedback. Make sure to call serov360_feedback(pin...
Definition: servo360_set.c:17