From 78e2b3cc0383a1f7161fae5da51827a248d39a42 Mon Sep 17 00:00:00 2001 From: Armin Date: Thu, 7 Apr 2022 22:33:00 +0200 Subject: [PATCH] Version 2.4.1 --- README.md | 2 +- .../AsymmetricEasing/AsymmetricEasing.ino | 2 +- .../AsymmetricEasing/PinDefinitionsAndMore.h | 2 +- examples/CatMover/CatMover.ino | 2 +- examples/CatMover/PinDefinitionsAndMore.h | 2 +- .../ContinuousRotatingServo.ino | 2 +- .../PinDefinitionsAndMore.h | 2 +- examples/EndPositionsTest/ADCUtils.cpp | 2 +- examples/EndPositionsTest/ADCUtils.h | 2 +- .../EndPositionsTest/EndPositionsTest.ino | 2 +- .../EndPositionsTest/PinDefinitionsAndMore.h | 2 +- .../LightweightServoExample.ino | 2 +- .../PinDefinitionsAndMore.h | 2 +- examples/OneServo/OneServo.ino | 2 +- examples/OneServo/PinDefinitionsAndMore.h | 2 +- .../PCA9685_Expander/PCA9685_Expander.ino | 2 +- .../PCA9685_ExpanderAndServo.ino | 2 +- .../PCA9685_ExpanderFor32Servos.ino | 2 +- examples/QuadrupedControl/ADCUtils.cpp | 2 +- examples/QuadrupedControl/ADCUtils.h | 2 +- examples/QuadrupedControl/HCSR04.cpp | 2 +- examples/QuadrupedControl/HCSR04.h | 2 +- .../QuadrupedControl/IRCommandDispatcher.h | 2 +- .../QuadrupedControl/IRCommandDispatcher.hpp | 2 +- examples/QuadrupedControl/IRCommandMapping.h | 14 +- .../QuadrupedBasicMovements.h | 36 +++- .../QuadrupedBasicMovements.hpp | 34 ++-- .../QuadrupedControl/QuadrupedConfiguration.h | 22 +- .../QuadrupedControl/QuadrupedControl.ino | 20 +- .../QuadrupedControlCommands.h | 40 +--- .../QuadrupedControlCommands.hpp | 189 ++++-------------- examples/QuadrupedControl/QuadrupedHelper.cpp | 122 ++++++++++- examples/QuadrupedControl/QuadrupedHelper.h | 3 + .../QuadrupedServoConfiguration.h | 7 +- .../QuadrupedControl/QuadrupedServoControl.h | 6 +- .../QuadrupedServoControl.hpp | 8 +- examples/QuadrupedControl/UserCommands.cpp | 5 +- examples/RobotArmControl/ADCUtils.cpp | 2 +- examples/RobotArmControl/ADCUtils.h | 2 +- examples/RobotArmControl/EasyButtonAtInt01.h | 2 +- .../RobotArmControl/EasyButtonAtInt01.hpp | 2 +- examples/RobotArmControl/RobotArmControl.ino | 2 +- .../RobotArmControl/RobotArmIRCommands.cpp | 2 +- .../RobotArmControl/RobotArmKinematics.cpp | 2 +- examples/Simple/PinDefinitionsAndMore.h | 2 +- examples/Simple/Simple.ino | 2 +- examples/SpeedTest/ADCUtils.cpp | 2 +- examples/SpeedTest/ADCUtils.h | 2 +- examples/SpeedTest/PinDefinitionsAndMore.h | 2 +- examples/SpeedTest/SpeedTest.ino | 2 +- .../SymmetricEasing/PinDefinitionsAndMore.h | 2 +- examples/SymmetricEasing/SymmetricEasing.ino | 2 +- examples/ThreeServos/PinDefinitionsAndMore.h | 2 +- examples/ThreeServos/ThreeServos.ino | 2 +- examples/TwoServos/PinDefinitionsAndMore.h | 2 +- examples/TwoServos/TwoServos.ino | 2 +- src/LightweightServo.h | 2 +- src/LightweightServo.hpp | 2 +- src/ServoEasing.h | 2 +- src/ServoEasing.hpp | 2 +- 60 files changed, 306 insertions(+), 294 deletions(-) diff --git a/README.md b/README.md index c366bc2..971e66d 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ To customize the library to different requirements, there are some compile optio These macros must be defined in your program before the line `#include ` to take effect.
Modify them by enabling / disabling them, or change the values if applicable. -| Option | Default | Description | +| Name | Default value | Description | |-|-|-| | `USE_PCA9685_SERVO_EXPANDER` | disabled | Enables the use of the PCA9685 I2C expander chip/board. | | `USE_SERVO_LIB` | disabled | Use of PCA9685 normally disables use of regular servo library. You can force additional using of regular servo library by defining `USE_SERVO_LIB`. See [below](https://github.com/ArminJo/ServoEasing#using-pca9685-16-channel-servo-expander). | diff --git a/examples/AsymmetricEasing/AsymmetricEasing.ino b/examples/AsymmetricEasing/AsymmetricEasing.ino index d596a0b..a5435c6 100644 --- a/examples/AsymmetricEasing/AsymmetricEasing.ino +++ b/examples/AsymmetricEasing/AsymmetricEasing.ino @@ -19,7 +19,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include diff --git a/examples/AsymmetricEasing/PinDefinitionsAndMore.h b/examples/AsymmetricEasing/PinDefinitionsAndMore.h index 62ade87..0e89623 100644 --- a/examples/AsymmetricEasing/PinDefinitionsAndMore.h +++ b/examples/AsymmetricEasing/PinDefinitionsAndMore.h @@ -20,7 +20,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/examples/CatMover/CatMover.ino b/examples/CatMover/CatMover.ino index 240c724..9d7995c 100644 --- a/examples/CatMover/CatMover.ino +++ b/examples/CatMover/CatMover.ino @@ -19,7 +19,7 @@ * GNU General Public License for more details. * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/examples/CatMover/PinDefinitionsAndMore.h b/examples/CatMover/PinDefinitionsAndMore.h index 62ade87..0e89623 100644 --- a/examples/CatMover/PinDefinitionsAndMore.h +++ b/examples/CatMover/PinDefinitionsAndMore.h @@ -20,7 +20,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/examples/ContinuousRotatingServo/ContinuousRotatingServo.ino b/examples/ContinuousRotatingServo/ContinuousRotatingServo.ino index 92b00c9..88ac675 100644 --- a/examples/ContinuousRotatingServo/ContinuousRotatingServo.ino +++ b/examples/ContinuousRotatingServo/ContinuousRotatingServo.ino @@ -19,7 +19,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include diff --git a/examples/ContinuousRotatingServo/PinDefinitionsAndMore.h b/examples/ContinuousRotatingServo/PinDefinitionsAndMore.h index 62ade87..0e89623 100644 --- a/examples/ContinuousRotatingServo/PinDefinitionsAndMore.h +++ b/examples/ContinuousRotatingServo/PinDefinitionsAndMore.h @@ -20,7 +20,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/examples/EndPositionsTest/ADCUtils.cpp b/examples/EndPositionsTest/ADCUtils.cpp index 557f233..c9c47a5 100644 --- a/examples/EndPositionsTest/ADCUtils.cpp +++ b/examples/EndPositionsTest/ADCUtils.cpp @@ -19,7 +19,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include "ADCUtils.h" diff --git a/examples/EndPositionsTest/ADCUtils.h b/examples/EndPositionsTest/ADCUtils.h index a1015c9..b0874fc 100644 --- a/examples/EndPositionsTest/ADCUtils.h +++ b/examples/EndPositionsTest/ADCUtils.h @@ -17,7 +17,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/examples/EndPositionsTest/EndPositionsTest.ino b/examples/EndPositionsTest/EndPositionsTest.ino index c8f3684..776ca40 100644 --- a/examples/EndPositionsTest/EndPositionsTest.ino +++ b/examples/EndPositionsTest/EndPositionsTest.ino @@ -27,7 +27,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include diff --git a/examples/EndPositionsTest/PinDefinitionsAndMore.h b/examples/EndPositionsTest/PinDefinitionsAndMore.h index 62ade87..0e89623 100644 --- a/examples/EndPositionsTest/PinDefinitionsAndMore.h +++ b/examples/EndPositionsTest/PinDefinitionsAndMore.h @@ -20,7 +20,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/examples/LightweightServoExample/LightweightServoExample.ino b/examples/LightweightServoExample/LightweightServoExample.ino index e322218..3d7900b 100644 --- a/examples/LightweightServoExample/LightweightServoExample.ino +++ b/examples/LightweightServoExample/LightweightServoExample.ino @@ -19,7 +19,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/examples/LightweightServoExample/PinDefinitionsAndMore.h b/examples/LightweightServoExample/PinDefinitionsAndMore.h index 62ade87..0e89623 100644 --- a/examples/LightweightServoExample/PinDefinitionsAndMore.h +++ b/examples/LightweightServoExample/PinDefinitionsAndMore.h @@ -20,7 +20,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/examples/OneServo/OneServo.ino b/examples/OneServo/OneServo.ino index 3655bd1..f2c7abd 100644 --- a/examples/OneServo/OneServo.ino +++ b/examples/OneServo/OneServo.ino @@ -19,7 +19,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include diff --git a/examples/OneServo/PinDefinitionsAndMore.h b/examples/OneServo/PinDefinitionsAndMore.h index 62ade87..0e89623 100644 --- a/examples/OneServo/PinDefinitionsAndMore.h +++ b/examples/OneServo/PinDefinitionsAndMore.h @@ -20,7 +20,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/examples/PCA9685_Expander/PCA9685_Expander.ino b/examples/PCA9685_Expander/PCA9685_Expander.ino index b931196..fa67b60 100644 --- a/examples/PCA9685_Expander/PCA9685_Expander.ino +++ b/examples/PCA9685_Expander/PCA9685_Expander.ino @@ -31,7 +31,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include diff --git a/examples/PCA9685_ExpanderAndServo/PCA9685_ExpanderAndServo.ino b/examples/PCA9685_ExpanderAndServo/PCA9685_ExpanderAndServo.ino index 4a13774..274c2f1 100644 --- a/examples/PCA9685_ExpanderAndServo/PCA9685_ExpanderAndServo.ino +++ b/examples/PCA9685_ExpanderAndServo/PCA9685_ExpanderAndServo.ino @@ -32,7 +32,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include diff --git a/examples/PCA9685_ExpanderFor32Servos/PCA9685_ExpanderFor32Servos.ino b/examples/PCA9685_ExpanderFor32Servos/PCA9685_ExpanderFor32Servos.ino index 58e95e6..4f120d2 100644 --- a/examples/PCA9685_ExpanderFor32Servos/PCA9685_ExpanderFor32Servos.ino +++ b/examples/PCA9685_ExpanderFor32Servos/PCA9685_ExpanderFor32Servos.ino @@ -31,7 +31,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include diff --git a/examples/QuadrupedControl/ADCUtils.cpp b/examples/QuadrupedControl/ADCUtils.cpp index 557f233..c9c47a5 100644 --- a/examples/QuadrupedControl/ADCUtils.cpp +++ b/examples/QuadrupedControl/ADCUtils.cpp @@ -19,7 +19,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include "ADCUtils.h" diff --git a/examples/QuadrupedControl/ADCUtils.h b/examples/QuadrupedControl/ADCUtils.h index a1015c9..b0874fc 100644 --- a/examples/QuadrupedControl/ADCUtils.h +++ b/examples/QuadrupedControl/ADCUtils.h @@ -17,7 +17,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/examples/QuadrupedControl/HCSR04.cpp b/examples/QuadrupedControl/HCSR04.cpp index a3dbdb3..a9f416f 100644 --- a/examples/QuadrupedControl/HCSR04.cpp +++ b/examples/QuadrupedControl/HCSR04.cpp @@ -49,7 +49,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/examples/QuadrupedControl/HCSR04.h b/examples/QuadrupedControl/HCSR04.h index fb898e2..73ddd71 100644 --- a/examples/QuadrupedControl/HCSR04.h +++ b/examples/QuadrupedControl/HCSR04.h @@ -25,7 +25,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/examples/QuadrupedControl/IRCommandDispatcher.h b/examples/QuadrupedControl/IRCommandDispatcher.h index a9b275a..27c5ac4 100644 --- a/examples/QuadrupedControl/IRCommandDispatcher.h +++ b/examples/QuadrupedControl/IRCommandDispatcher.h @@ -23,7 +23,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #ifndef _IR_COMMAND_DISPATCHER_H diff --git a/examples/QuadrupedControl/IRCommandDispatcher.hpp b/examples/QuadrupedControl/IRCommandDispatcher.hpp index 7878274..8949e33 100644 --- a/examples/QuadrupedControl/IRCommandDispatcher.hpp +++ b/examples/QuadrupedControl/IRCommandDispatcher.hpp @@ -29,7 +29,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #ifndef _IR_COMMAND_DISPATCHER_HPP #define _IR_COMMAND_DISPATCHER_HPP diff --git a/examples/QuadrupedControl/IRCommandMapping.h b/examples/QuadrupedControl/IRCommandMapping.h index bc0accb..2f2dbf3 100644 --- a/examples/QuadrupedControl/IRCommandMapping.h +++ b/examples/QuadrupedControl/IRCommandMapping.h @@ -11,12 +11,15 @@ * Select the one you have below. */ -#ifndef IR_COMMAND_MAPPING_H_ -#define IR_COMMAND_MAPPING_H_ +#ifndef _IR_COMMAND_MAPPING_H +#define _IR_COMMAND_MAPPING_H #include +#include "IRCommandDispatcher.h" // IR_COMMAND_FLAG_BLOCKING etc. are defined here #include "QuadrupedControlCommands.h" // contains the command definitions used in the mapping table below +#include "QuadrupedHelper.h" // for additional commands +#include "QuadrupedNeoPixel.h" // for additional commands /* * !!! Choose your remote !!! @@ -284,11 +287,9 @@ #endif #if defined(USE_WHITE_DVD_REMOTE) -#include "QuadrupedNeoPixel.h" // for additional commands -#include "QuadrupedHelper.h" // for additional commands # if defined(IR_REMOTE_NAME) #error "Please choose only one remote for compile" -# elsef +# else #define IR_REMOTE_NAME "WHITE_DVD" #define HAS_ADDITIONAL_REMOTE_COMMANDS @@ -477,6 +478,5 @@ COMMAND_STOP, IR_COMMAND_FLAG_IS_STOP_COMMAND, &doStop, stop } #endif }; -#endif /* IR_COMMAND_MAPPING_H_ */ - +#endif // _IR_COMMAND_MAPPING_H #pragma once diff --git a/examples/QuadrupedControl/QuadrupedBasicMovements.h b/examples/QuadrupedControl/QuadrupedBasicMovements.h index a7b6553..82b2247 100644 --- a/examples/QuadrupedControl/QuadrupedBasicMovements.h +++ b/examples/QuadrupedControl/QuadrupedBasicMovements.h @@ -5,8 +5,8 @@ * Author: Armin */ -#ifndef QUADRUPED_BASIC_MOVEMENTS_H -#define QUADRUPED_BASIC_MOVEMENTS_H +#ifndef _QUADRUPED_BASIC_MOVEMENTS_H +#define _QUADRUPED_BASIC_MOVEMENTS_H #include "QuadrupedServoConfiguration.h" // for MOVE_DIRECTION_FORWARD @@ -14,6 +14,35 @@ extern volatile uint8_t sMovingDirection; +#if ! defined(QUADRUPED_MOVEMENT_BREAK_FLAG) +#define QUADRUPED_MOVEMENT_BREAK_FLAG false +#endif +#if ! defined(QUADRUPED_BREAK_IF_STOP) +#define QUADRUPED_BREAK_IF_STOP if (QUADRUPED_MOVEMENT_BREAK_FLAG) break +#endif +#if ! defined(QUADRUPED_RETURN_IF_STOP) +#define QUADRUPED_RETURN_IF_STOP if (QUADRUPED_MOVEMENT_BREAK_FLAG) return +#endif + +/* + * Action type definitions + * Currently used for NeoPatterns display + */ +#define ACTION_TYPE_STOP 0 +#define ACTION_TYPE_CREEP 1 +#define ACTION_TYPE_TROT 2 +#define ACTION_TYPE_TURN 3 +#define ACTION_TYPE_TWIST 4 +#define ACTION_TYPE_ATTENTION 5 +#define ACTION_TYPE_LEAN 6 +#define ACTION_TYPE_WAVE 7 +// only used by UserCommands.cpp +#define ACTION_TYPE_DANCE 8 +#define ACTION_TYPE_TEST 9 +#define ACTION_TYPE_AUTO_MOVE 10 +extern uint8_t sCurrentlyRunningAction; // A change on this action type triggers the generation of new neopatterns +extern uint8_t sLastActionTypeForNeopatternsDisplay; // do determine changes of sCurrentlyRunningAction + /* * Movements */ @@ -24,6 +53,5 @@ void moveTurn(uint8_t aNumberOfTurns = 0); // 0 -> 256 turns void moveTrot(uint8_t aNumberOfTrots = 0); // 0 -> 256 trots void moveCreep(uint8_t aNumberOfCreeps = 0); // 0 -> 256 creeps -#endif /* QUADRUPED_BASIC_MOVEMENTS_H */ - +#endif // _QUADRUPED_BASIC_MOVEMENTS_H #pragma once diff --git a/examples/QuadrupedControl/QuadrupedBasicMovements.hpp b/examples/QuadrupedControl/QuadrupedBasicMovements.hpp index d23c475..0fa2d94 100644 --- a/examples/QuadrupedControl/QuadrupedBasicMovements.hpp +++ b/examples/QuadrupedControl/QuadrupedBasicMovements.hpp @@ -19,22 +19,24 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ -#ifndef QUADRUPED_BASIC_MOVEMENTS_HPP -#define QUADRUPED_BASIC_MOVEMENTS_HPP +#ifndef _QUADRUPED_BASIC_MOVEMENTS_HPP +#define _QUADRUPED_BASIC_MOVEMENTS_HPP #include #include "QuadrupedBasicMovements.h" -#include "QuadrupedControlCommands.h" #include "QuadrupedServoControl.h" //#define INFO // activate this to see serial info output volatile uint8_t sMovingDirection = MOVE_DIRECTION_FORWARD; +uint8_t sCurrentlyRunningAction; // A change on this action type triggers the generation of new NeoPatterns +uint8_t sLastActionTypeForNeopatternsDisplay; // do determine changes of sCurrentlyRunningAction + /* * Gait variations * 1. Creep: Move one leg forward and down, then move body with all 4 legs down, then move diagonal leg. @@ -55,7 +57,7 @@ void moveTrot(uint8_t aNumberOfTrots) { transformAndSetAllServos(TROT_BASE_ANGLE_FL_BR + TROT_MOVE_ANGLE, TROT_BASE_ANGLE_BL_FR - TROT_MOVE_ANGLE, TROT_BASE_ANGLE_FL_BR - TROT_MOVE_ANGLE, TROT_BASE_ANGLE_BL_FR + TROT_MOVE_ANGLE, tRequestedBodyHeightAngle, LiftMaxAngle, tRequestedBodyHeightAngle, LiftMaxAngle, tCurrentDirection); - BREAK_IF_STOP; + QUADRUPED_BREAK_IF_STOP; tRequestedBodyHeightAngle = sRequestedBodyHeightAngle; @@ -63,7 +65,7 @@ void moveTrot(uint8_t aNumberOfTrots) { transformAndSetAllServos(TROT_BASE_ANGLE_FL_BR - TROT_MOVE_ANGLE, TROT_BASE_ANGLE_BL_FR + TROT_MOVE_ANGLE, TROT_BASE_ANGLE_FL_BR + TROT_MOVE_ANGLE, TROT_BASE_ANGLE_BL_FR - TROT_MOVE_ANGLE, LiftMaxAngle, tRequestedBodyHeightAngle, LiftMaxAngle, tRequestedBodyHeightAngle, tCurrentDirection); - BREAK_IF_STOP; + QUADRUPED_BREAK_IF_STOP; aNumberOfTrots--; } while (aNumberOfTrots != 0); @@ -110,7 +112,7 @@ void moveTurn(uint8_t aNumberOfBasicTurns) { // do at least one basic turn do { - BREAK_IF_STOP; + QUADRUPED_BREAK_IF_STOP; basicTurn(tNextLiftLegIndex, sMovingDirection == MOVE_DIRECTION_LEFT); /* * get next index of leg which must be lifted @@ -201,10 +203,10 @@ void moveCreep(uint8_t aNumberOfCreeps) { uint8_t tCurrentDirection = sMovingDirection; basicHalfCreep(tCurrentDirection, false); - BREAK_IF_STOP; + QUADRUPED_BREAK_IF_STOP; // now mirror movement basicHalfCreep(tCurrentDirection, true); - BREAK_IF_STOP; + QUADRUPED_BREAK_IF_STOP; aNumberOfCreeps--; } while (aNumberOfCreeps != 0); @@ -231,7 +233,7 @@ void basicHalfCreep(uint8_t aDirection, bool doMirror) { transformAndSetAllServos(180 - Y_POSITION_OPEN_ANGLE, Y_POSITION_OPEN_ANGLE, 180 - Y_POSITION_CLOSE_ANGLE, Y_POSITION_FRONT_ANGLE, tRequestedBodyHeightAngle, tRequestedBodyHeightAngle, tRequestedBodyHeightAngle, LIFT_HIGHEST_ANGLE, aDirection, doMirror); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; tRequestedBodyHeightAngle = sRequestedBodyHeightAngle; @@ -242,7 +244,7 @@ void basicHalfCreep(uint8_t aDirection, bool doMirror) { transformAndSetAllServos(180 - Y_POSITION_CLOSE_ANGLE, Y_POSITION_OPEN_ANGLE + CREEP_BODY_MOVE_ANGLE, 180 - Y_POSITION_OPEN_ANGLE, Y_POSITION_OPEN_ANGLE, tRequestedBodyHeightAngle, tRequestedBodyHeightAngle, tRequestedBodyHeightAngle, tRequestedBodyHeightAngle, aDirection, doMirror); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; tRequestedBodyHeightAngle = sRequestedBodyHeightAngle; @@ -287,17 +289,17 @@ void basicSimpleHalfCreep(uint8_t aLeftLegIndex, bool aMoveMirrored) { Serial.println(F("1. move front leg")); #endif moveOneServoAndCheckInputAndWait(tLeftLegPivotServoIndex + LIFT_SERVO_OFFSET, LIFT_HIGHEST_ANGLE); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; // go CREEP_BODY_MOVE_ANGLE ahead of Y_POSITION_OPEN_ANGLE aMoveMirrored ? tEffectiveAngle = 180 - (Y_POSITION_OPEN_ANGLE - CREEP_BODY_MOVE_ANGLE) : tEffectiveAngle = Y_POSITION_OPEN_ANGLE - CREEP_BODY_MOVE_ANGLE; moveOneServoAndCheckInputAndWait(tLeftLegPivotServoIndex, tEffectiveAngle); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; moveOneServoAndCheckInputAndWait(tLeftLegPivotServoIndex + LIFT_SERVO_OFFSET, sRequestedBodyHeightAngle); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; // 2. Move body forward #if defined(INFO) @@ -346,11 +348,11 @@ void basicSimpleHalfCreep(uint8_t aLeftLegIndex, bool aMoveMirrored) { // Move to Y position with right legs together / 120, 60, 180, 0 uint8_t tDiagonalIndex = (tLeftLegPivotServoIndex + DIAGONAL_SERVO_OFFSET) % NUMBER_OF_SERVOS; moveOneServoAndCheckInputAndWait(tDiagonalIndex + LIFT_SERVO_OFFSET, LIFT_HIGHEST_ANGLE); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; aMoveMirrored ? tEffectiveAngle = 180 - Y_POSITION_CLOSE_ANGLE : tEffectiveAngle = Y_POSITION_CLOSE_ANGLE; moveOneServoAndCheckInputAndWait(tDiagonalIndex, tEffectiveAngle); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; moveOneServoAndCheckInputAndWait(tDiagonalIndex + LIFT_SERVO_OFFSET, sRequestedBodyHeightAngle); } diff --git a/examples/QuadrupedControl/QuadrupedConfiguration.h b/examples/QuadrupedControl/QuadrupedConfiguration.h index c16713e..cbf7660 100644 --- a/examples/QuadrupedControl/QuadrupedConfiguration.h +++ b/examples/QuadrupedControl/QuadrupedConfiguration.h @@ -7,19 +7,19 @@ * Author: Armin */ -#ifndef QUADRUPED_CONFIGURATION_H_ -#define QUADRUPED_CONFIGURATION_H_ +#ifndef _QUADRUPED_CONFIGURATION_H +#define _QUADRUPED_CONFIGURATION_H #define PIN_BUZZER 3 #define VCC_STOP_THRESHOLD_MILLIVOLT 3500 // stop moving if below 3.5 volt -//#define QUADRUPED_HAS_IR_CONTROL // 8600 bytes (including the movements) -//#define QUADRUPED_ENABLE_RTTTL // 1300 bytes for Short + Down -//#define QUADRUPED_HAS_NEOPIXEL // 6300 to 6600 bytes -//#define QUADRUPED_HAS_US_DISTANCE // 800 bytes -//#define QUADRUPED_HAS_US_DISTANCE_SERVO // 710 bytes -//#define INFO // 2850 bytes +//#define QUADRUPED_HAS_IR_CONTROL // Requires additionally 8600 bytes (including the movements) +//#define QUADRUPED_ENABLE_RTTTL // Requires additionally 1300 bytes for Short + Down +//#define QUADRUPED_HAS_NEOPIXEL // Requires additionally 6300 to 6600 bytes +//#define QUADRUPED_HAS_US_DISTANCE // Requires additionally 800 bytes +//#define QUADRUPED_HAS_US_DISTANCE_SERVO // Requires additionally 710 bytes +//#define INFO // Requires additionally 2850 bytes /* * !!! Choose your remote !!! @@ -89,10 +89,6 @@ extern Servo USServo; # endif #endif -#if defined(QUADRUPED_ENABLE_RTTTL) -#include -#endif - #if defined(QUADRUPED_HAS_NEOPIXEL) // patterns always used if Neopixel are enabled #define ENABLE_PATTERN_HEARTBEAT @@ -107,5 +103,5 @@ extern Servo USServo; */ bool delayAndCheckForLowVoltageAndStop(uint16_t aDelayMillis); -#endif /* QUADRUPED_CONFIGURATION_H_ */ +#endif // _QUADRUPED_CONFIGURATION_H #pragma once diff --git a/examples/QuadrupedControl/QuadrupedControl.ino b/examples/QuadrupedControl/QuadrupedControl.ino index bf12ca5..d7ca725 100644 --- a/examples/QuadrupedControl/QuadrupedControl.ino +++ b/examples/QuadrupedControl/QuadrupedControl.ino @@ -29,23 +29,31 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include #include "QuadrupedConfiguration.h" -#include "QuadrupedServoControl.hpp" -#include "QuadrupedBasicMovements.hpp" +#if defined(QUADRUPED_HAS_IR_CONTROL) +// Include the header only IRCommandDispatcher library in the main program +#include "IRCommandMapping.h" // Must be included before IRCommandDispatcher.hpp to define IR_ADDRESS and IRMapping and string "unknown". +#include "IRCommandDispatcher.hpp" +#define QUADRUPED_MOVEMENT_BREAK_FLAG (IRDispatcher.requestToStopReceived) +#endif + #include "QuadrupedControlCommands.hpp" // Commands can also be used e.g. in loop(). +#if defined(QUADRUPED_HAS_NEOPIXEL) +#include "QuadrupedNeoPixel.hpp" +#endif #include "QuadrupedHelper.h" #include "ADCUtils.h" // for getVCCVoltageMillivoltSimple() and printVCCVoltageMillivolt() #if defined(QUADRUPED_HAS_US_DISTANCE) && defined(QUADRUPED_HAS_US_DISTANCE_SERVO) -Servo USServo; // Servo for US sensor use Servo library direct, we do nor require easings here ( and we have only 8 Servo easings allocated) +Servo USServo; // Servo for US sensor use Servo library direct, we do nor require easings here ( and we have only 8 Servo easings allocated) #define NO_LED_FEEDBACK_CODE // Disable IR LED feedback because servo is at the same pin. Must be included before IRCommandDispatcher.hpp #endif @@ -55,6 +63,10 @@ Servo USServo; // Servo for US sensor use Servo library direct, we do nor req #include "IRCommandDispatcher.hpp" #endif +#if defined(QUADRUPED_ENABLE_RTTTL) +#include +#endif + //#define INFO // activate this to see serial info output /* diff --git a/examples/QuadrupedControl/QuadrupedControlCommands.h b/examples/QuadrupedControl/QuadrupedControlCommands.h index a1e1935..903d1b7 100644 --- a/examples/QuadrupedControl/QuadrupedControlCommands.h +++ b/examples/QuadrupedControl/QuadrupedControlCommands.h @@ -7,41 +7,8 @@ * Author: Armin */ -#ifndef QUADRUPED_CONTROL_COMMANDS_H -#define QUADRUPED_CONTROL_COMMANDS_H - -// Definition of RETURN_IF_STOP and BREAK_IF_STOP macro -#if defined(QUADRUPED_HAS_IR_CONTROL) -#include "IRCommandDispatcher.h" // RETURN_IF_STOP and BREAK_IF_STOP are defined here -#else -# if defined(RETURN_IF_STOP) -#undef RETURN_IF_STOP -# endif -#define RETURN_IF_STOP // define as empty -# if defined(BREAK_IF_STOP) -#undef BREAK_IF_STOP -# endif -#define BREAK_IF_STOP // define as empty -#endif - -/* - * Action type definitions - * Currently used for NeoPatterns display - */ -#define ACTION_TYPE_STOP 0 -#define ACTION_TYPE_CREEP 1 -#define ACTION_TYPE_TROT 2 -#define ACTION_TYPE_TURN 3 -#define ACTION_TYPE_TWIST 4 -#define ACTION_TYPE_ATTENTION 5 -#define ACTION_TYPE_LEAN 6 -#define ACTION_TYPE_WAVE 7 -// only used by UserCommands.cpp -#define ACTION_TYPE_DANCE 8 -#define ACTION_TYPE_TEST 9 -#define ACTION_TYPE_AUTO_MOVE 10 -extern uint8_t sCurrentlyRunningAction; // A change on this action type triggers the generation of new neopatterns -extern uint8_t sLastActionTypeForNeopatternsDisplay; // do determine changes of sCurrentlyRunningAction +#ifndef _QUADRUPED_CONTROL_COMMANDS_H +#define _QUADRUPED_CONTROL_COMMANDS_H // The code for the called command is available in variable sCurrentIRCode // All functions have the prefix __attribute__((weak)) in order to enable easy overwriting with own functions. @@ -68,7 +35,6 @@ void doAttention(); // Special commands void doCenterServos(); -void doCalibration(); void doTest(); /* @@ -84,5 +50,5 @@ void doDecreaseSpeed(); void doIncreaseHeight(); void doDecreaseHeight(); -#endif /* QUADRUPED_CONTROL_COMMANDS_H */ +#endif // _QUADRUPED_CONTROL_COMMANDS_H #pragma once diff --git a/examples/QuadrupedControl/QuadrupedControlCommands.hpp b/examples/QuadrupedControl/QuadrupedControlCommands.hpp index b817745..dc49024 100644 --- a/examples/QuadrupedControl/QuadrupedControlCommands.hpp +++ b/examples/QuadrupedControl/QuadrupedControlCommands.hpp @@ -23,23 +23,20 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ -#ifndef QUADRUPED_CONTROL_COMMANDS_HPP -#define QUADRUPED_CONTROL_COMMANDS_HPP +#ifndef _QUADRUPED_CONTROL_COMMANDS_HPP +#define _QUADRUPED_CONTROL_COMMANDS_HPP #include #include "QuadrupedControlCommands.h" -#include "QuadrupedBasicMovements.h" -#include "QuadrupedServoControl.h" +#include "QuadrupedServoControl.hpp" +#include "QuadrupedBasicMovements.hpp" //#define INFO // activate this to see serial info output -uint8_t sCurrentlyRunningAction; // A change on this action type triggers the generation of new NeoPatterns -uint8_t sLastActionTypeForNeopatternsDisplay; // do determine changes of sCurrentlyRunningAction - /****************************************** * The Commands to execute ******************************************/ @@ -57,40 +54,40 @@ void __attribute__((weak)) doDance() { #endif centerServos(); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; /* * Move down and up and back to current height */ doAttention(); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; for (int i = 0; i < 1; ++i) { doLeanLeft(); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; doLeanRight(); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; } for (int i = 0; i < 3; ++i) { doLeanLeft(); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; // lean back doLeanBack(); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; uint8_t tTwistAngle = random(30, 60); basicTwist(tTwistAngle); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; basicTwist(tTwistAngle, false); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; doLeanRight(); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; // lean front doLeanFront(); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; } doWave(); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; centerServos(); } @@ -105,28 +102,28 @@ void __attribute__((weak)) doWave() { uint8_t tRequestedBodyHeightAngle = sRequestedBodyHeightAngle; // sRequestedBodyHeightAngle is volatile // move front left and back right leg 10 degree forward to avoid falling to front if lifting the front right leg setAllServos(80, 90, 100, 90, tRequestedBodyHeightAngle, tRequestedBodyHeightAngle, tRequestedBodyHeightAngle, tRequestedBodyHeightAngle); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; // move all legs up, except front left -> front right lifts from the ground setLiftServos(LIFT_LOWEST_ANGLE, LIFT_HIGHEST_ANGLE, LIFT_HIGHEST_ANGLE, LIFT_HIGHEST_ANGLE); delayAndCheckForLowVoltageAndStop(1000); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; ServoEasing::ServoEasingArray[FRONT_RIGHT_PIVOT]->setEasingType(EASE_QUADRATIC_IN_OUT); // wave with the front right leg for (uint_fast8_t i = 0; i < 3; ++i) { moveOneServoAndCheckInputAndWait(FRONT_RIGHT_PIVOT, 135, sQuadrupedServoSpeed * 2); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; moveOneServoAndCheckInputAndWait(FRONT_RIGHT_PIVOT, 45, sQuadrupedServoSpeed * 2); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; } ServoEasing::ServoEasingArray[FRONT_RIGHT_PIVOT]->setEasingType(EASE_LINEAR); delayAndCheckForLowVoltageAndStop(1000); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; centerServos(); sCurrentlyRunningAction = ACTION_TYPE_STOP; @@ -148,7 +145,7 @@ void __attribute__((weak)) doBow() { centerServos(); delayAndCheckForLowVoltageAndStop(300); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; // Lift front legs ServoEasing::ServoEasingArray[FRONT_LEFT_LIFT]->setEaseTo(LIFT_LOWEST_ANGLE, sQuadrupedServoSpeed); @@ -157,7 +154,7 @@ void __attribute__((weak)) doBow() { updateAndCheckInputAndWaitForAllServosToStop(); delayAndCheckForLowVoltageAndStop(300); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; centerServos(); } @@ -168,9 +165,9 @@ void __attribute__((weak)) doTwist() { printQuadrupedServoSpeed(); #endif basicTwist(30, true); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; basicTwist(30, false); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; centerServos(); } @@ -256,9 +253,9 @@ void __attribute__((weak)) doAttention() { #endif // Move down and up and back to starting height setLiftServos(LIFT_HIGHEST_ANGLE); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; setLiftServos(LIFT_LOWEST_ANGLE); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; setLiftServos(sRequestedBodyHeightAngle); sCurrentlyRunningAction = ACTION_TYPE_STOP; } @@ -270,70 +267,70 @@ void __attribute__((weak)) doQuadrupedAutoMove() { Serial.println(F("Start auto move sequence")); #endif centerServos(); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; // Move down and up and back to starting height doAttention(); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; // creep forward slow sMovingDirection = MOVE_DIRECTION_FORWARD; moveCreep(2); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; // creep forward fast setQuadrupedServoSpeed(260); moveCreep(6); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; // creep right fast sMovingDirection = MOVE_DIRECTION_RIGHT; moveCreep(8); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; // creep left fast sMovingDirection = MOVE_DIRECTION_LEFT; moveCreep(4); delayAndCheckForLowVoltageAndStop(2000); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; setQuadrupedServoSpeed(200); doDance(); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; // turn right sMovingDirection = MOVE_DIRECTION_RIGHT; // triggerNeoPatterns(); moveTurn(11); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; // trot forward setQuadrupedServoSpeed(160); sMovingDirection = MOVE_DIRECTION_FORWARD; centerServos(); moveTrot(10); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; // trot back sMovingDirection = MOVE_DIRECTION_BACKWARD; moveTrot(8); delayAndCheckForLowVoltageAndStop(2000); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; // trot right sMovingDirection = MOVE_DIRECTION_RIGHT; moveTrot(8); delayAndCheckForLowVoltageAndStop(2000); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; // turn right centerServos(); sMovingDirection = MOVE_DIRECTION_RIGHT; moveTurn(12); - RETURN_IF_STOP; + QUADRUPED_RETURN_IF_STOP; // restore speed setQuadrupedServoSpeed(tOriginalSpeed); @@ -428,111 +425,5 @@ void __attribute__((weak)) doDecreaseHeight() { } } -/* - * Special calibration command - */ - -/* - * Signals which leg is to be calibrated - */ -void signalLeg(uint8_t aPivotServoIndex) { - ServoEasing::ServoEasingArray[aPivotServoIndex + LIFT_SERVO_OFFSET]->easeTo(LIFT_HIGHEST_ANGLE, 60); - ServoEasing::ServoEasingArray[aPivotServoIndex]->easeTo(90, 60); - ServoEasing::ServoEasingArray[aPivotServoIndex + LIFT_SERVO_OFFSET]->easeTo(90, 60); -} - -#if defined(QUADRUPED_HAS_IR_CONTROL) && !defined(USE_USER_DEFINED_MOVEMENTS) -// Disable doCalibration() also for user defined movements, since just testing the remote may lead to accidental wrong calibration - -#include "IRCommandMapping.h" // for COMMAND_* definitions in doCalibration() - -/* - * Changes the servo calibration values in EEPROM. - * Starts with front left i.e. ServoEasing::ServoEasingArray[0,1] and switches to the next leg with the COMMAND_ENTER - * Is only available if IR control is attached - */ -void doCalibration() { - uint8_t tPivotServoIndex = 0; // start with front left i.e. ServoEasing::ServoEasingArray[0] - bool tGotExitCommand = false; - resetServosTo90Degree(); - delay(500); - signalLeg(tPivotServoIndex); -# if defined(INFO) - Serial.println(F("Entered calibration. Use the forward/backward right/left buttons to set the servo position to 90 degree.")); - Serial.println(F("Use enter/OK button to go to next leg. Values are stored at receiving a different button or after 4th leg.")); -# endif - - IRDispatcher.doNotUseDispatcher = true; // disable dispatcher by mapping table - while (!tGotExitCommand) { - // wait until next command received - while (!IRDispatcher.IRReceivedData.isAvailable) { - } - IRDispatcher.IRReceivedData.isAvailable = false; - - unsigned long tIRCode = IRDispatcher.IRReceivedData.command; -# if defined(INFO) - IRDispatcher.printIRCommandString(&Serial); -# endif - switch (tIRCode) { - case COMMAND_RIGHT: - sServoTrimAngles[tPivotServoIndex]++; - ServoEasing::ServoEasingArray[tPivotServoIndex]->setTrim(sServoTrimAngles[tPivotServoIndex], true); - break; - case COMMAND_LEFT: - sServoTrimAngles[tPivotServoIndex]--; - ServoEasing::ServoEasingArray[tPivotServoIndex]->setTrim(sServoTrimAngles[tPivotServoIndex], true); - break; - case COMMAND_FORWARD: - sServoTrimAngles[tPivotServoIndex + LIFT_SERVO_OFFSET]++; - ServoEasing::ServoEasingArray[tPivotServoIndex + LIFT_SERVO_OFFSET]->setTrim( - sServoTrimAngles[tPivotServoIndex + LIFT_SERVO_OFFSET], true); - break; - case COMMAND_BACKWARD: - sServoTrimAngles[tPivotServoIndex + LIFT_SERVO_OFFSET]--; - ServoEasing::ServoEasingArray[tPivotServoIndex + LIFT_SERVO_OFFSET]->setTrim( - sServoTrimAngles[tPivotServoIndex + LIFT_SERVO_OFFSET], true); - break; - case COMMAND_ENTER: - // show 135 and 45 degree positions - ServoEasing::ServoEasingArray[tPivotServoIndex]->easeTo(135, 100); - delay(2000); - ServoEasing::ServoEasingArray[tPivotServoIndex]->easeTo(45, 100); - delay(2000); - ServoEasing::ServoEasingArray[tPivotServoIndex]->easeTo(90, 100); - tPivotServoIndex += SERVOS_PER_LEG; - eepromWriteServoTrim(); - if (tPivotServoIndex >= NUMBER_OF_SERVOS) { - tGotExitCommand = true; - } else { - signalLeg(tPivotServoIndex); - } - break; - case COMMAND_CALIBRATE: - // repeated command here - break; - default: - eepromWriteServoTrim(); - tGotExitCommand = true; - break; - } -# if defined(INFO) - Serial.print(F("ServoTrimAngles[")); - Serial.print(tPivotServoIndex); - Serial.print(F("]=")); - Serial.print(sServoTrimAngles[tPivotServoIndex]); - Serial.print(F(" [")); - Serial.print(tPivotServoIndex + LIFT_SERVO_OFFSET); - Serial.print(F("]=")); - Serial.println(sServoTrimAngles[tPivotServoIndex + LIFT_SERVO_OFFSET]); -# endif - ServoEasing::ServoEasingArray[tPivotServoIndex]->print(&Serial); - ServoEasing::ServoEasingArray[tPivotServoIndex + LIFT_SERVO_OFFSET]->print(&Serial); - delay(200); - } - IRDispatcher.doNotUseDispatcher = false; // re enable dispatcher by mapping table - -} -#endif - -#endif /* QUADRUPED_CONTROL_COMMANDS_HPP */ +#endif // _QUADRUPED_CONTROL_COMMANDS_HPP #pragma once diff --git a/examples/QuadrupedControl/QuadrupedHelper.cpp b/examples/QuadrupedControl/QuadrupedHelper.cpp index 91761d9..1ef9dac 100644 --- a/examples/QuadrupedControl/QuadrupedHelper.cpp +++ b/examples/QuadrupedControl/QuadrupedHelper.cpp @@ -19,19 +19,29 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include #include "QuadrupedConfiguration.h" #include "ADCUtils.h" // for getVCCVoltageMillivoltSimple() -#include "QuadrupedControlCommands.h" // for sCurrentlyRunningAction +#include "QuadrupedBasicMovements.h" // for sCurrentlyRunningAction #if defined(QUADRUPED_HAS_NEOPIXEL) #include "QuadrupedNeoPixel.h" #endif +#if defined(QUADRUPED_ENABLE_RTTTL) +#define SUPPRESS_HPP_WARNING +#include +#endif + +#if defined(QUADRUPED_HAS_IR_CONTROL) +#include "IRCommandDispatcher.h" +#include "QuadrupedServoControl.h" +#endif + #if !defined(STR_HELPER) #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) @@ -111,7 +121,8 @@ void handleUSSensor() { } #endif // #if defined(QUADRUPED_HAS_US_DISTANCE) -#if defined(QUADRUPED_HAS_US_DISTANCE_SERVO) +#if defined(QUADRUPED_HAS_IR_CONTROL) +# if defined(QUADRUPED_HAS_US_DISTANCE_SERVO) #define SERVO_INCREMENT 10 void doUSRight() { if (!IRDispatcher.IRReceivedData.isRepeat && USServo.read() >= SERVO_INCREMENT) { @@ -128,7 +139,110 @@ void doUSScan() { USServo.write(90); } } -#endif +# endif + +# if !defined(USE_USER_DEFINED_MOVEMENTS) +// Disable doCalibration() also for user defined movements, since just testing the remote may lead to accidental wrong calibration + +#include "IRCommandMapping.h" // for COMMAND_* definitions in doCalibration() + +/* + * Signals which leg is to be calibrated + */ +void signalLeg(uint8_t aPivotServoIndex) { + ServoEasing::ServoEasingArray[aPivotServoIndex + LIFT_SERVO_OFFSET]->easeTo(LIFT_HIGHEST_ANGLE, 60); + ServoEasing::ServoEasingArray[aPivotServoIndex]->easeTo(90, 60); + ServoEasing::ServoEasingArray[aPivotServoIndex + LIFT_SERVO_OFFSET]->easeTo(90, 60); +} + +/* + * Changes the servo calibration values in EEPROM. + * Starts with front left i.e. ServoEasing::ServoEasingArray[0,1] and switches to the next leg with the COMMAND_ENTER + * Is only available if IR control is attached + */ +void doCalibration() { + uint8_t tPivotServoIndex = 0; // start with front left i.e. ServoEasing::ServoEasingArray[0] + bool tGotExitCommand = false; + resetServosTo90Degree(); + delay(500); + signalLeg(tPivotServoIndex); +# if defined(INFO) + Serial.println(F("Entered calibration. Use the forward/backward right/left buttons to set the servo position to 90 degree.")); + Serial.println(F("Use enter/OK button to go to next leg. Values are stored at receiving a different button or after 4th leg.")); +# endif + + IRDispatcher.doNotUseDispatcher = true; // disable dispatcher by mapping table + while (!tGotExitCommand) { + // wait until next command received + while (!IRDispatcher.IRReceivedData.isAvailable) { + } + IRDispatcher.IRReceivedData.isAvailable = false; + + unsigned long tIRCode = IRDispatcher.IRReceivedData.command; +# if defined(INFO) + IRDispatcher.printIRCommandString(&Serial); +# endif + switch (tIRCode) { + case COMMAND_RIGHT: + sServoTrimAngles[tPivotServoIndex]++; + ServoEasing::ServoEasingArray[tPivotServoIndex]->setTrim(sServoTrimAngles[tPivotServoIndex], true); + break; + case COMMAND_LEFT: + sServoTrimAngles[tPivotServoIndex]--; + ServoEasing::ServoEasingArray[tPivotServoIndex]->setTrim(sServoTrimAngles[tPivotServoIndex], true); + break; + case COMMAND_FORWARD: + sServoTrimAngles[tPivotServoIndex + LIFT_SERVO_OFFSET]++; + ServoEasing::ServoEasingArray[tPivotServoIndex + LIFT_SERVO_OFFSET]->setTrim( + sServoTrimAngles[tPivotServoIndex + LIFT_SERVO_OFFSET], true); + break; + case COMMAND_BACKWARD: + sServoTrimAngles[tPivotServoIndex + LIFT_SERVO_OFFSET]--; + ServoEasing::ServoEasingArray[tPivotServoIndex + LIFT_SERVO_OFFSET]->setTrim( + sServoTrimAngles[tPivotServoIndex + LIFT_SERVO_OFFSET], true); + break; + case COMMAND_ENTER: + // show 135 and 45 degree positions + ServoEasing::ServoEasingArray[tPivotServoIndex]->easeTo(135, 100); + delay(2000); + ServoEasing::ServoEasingArray[tPivotServoIndex]->easeTo(45, 100); + delay(2000); + ServoEasing::ServoEasingArray[tPivotServoIndex]->easeTo(90, 100); + tPivotServoIndex += SERVOS_PER_LEG; + eepromWriteServoTrim(); + if (tPivotServoIndex >= NUMBER_OF_SERVOS) { + tGotExitCommand = true; + } else { + signalLeg(tPivotServoIndex); + } + break; + case COMMAND_CALIBRATE: + // repeated command here + break; + default: + eepromWriteServoTrim(); + tGotExitCommand = true; + break; + } +# if defined(INFO) + Serial.print(F("ServoTrimAngles[")); + Serial.print(tPivotServoIndex); + Serial.print(F("]=")); + Serial.print(sServoTrimAngles[tPivotServoIndex]); + Serial.print(F(" [")); + Serial.print(tPivotServoIndex + LIFT_SERVO_OFFSET); + Serial.print(F("]=")); + Serial.println(sServoTrimAngles[tPivotServoIndex + LIFT_SERVO_OFFSET]); +# endif + ServoEasing::ServoEasingArray[tPivotServoIndex]->print(&Serial); + ServoEasing::ServoEasingArray[tPivotServoIndex + LIFT_SERVO_OFFSET]->print(&Serial); + delay(200); + } + IRDispatcher.doNotUseDispatcher = false; // re enable dispatcher by mapping table + +} +# endif // !defined(USE_USER_DEFINED_MOVEMENTS) +#endif // defined(QUADRUPED_HAS_IR_CONTROL) /* * Special delay function for the quadruped control. diff --git a/examples/QuadrupedControl/QuadrupedHelper.h b/examples/QuadrupedControl/QuadrupedHelper.h index f1fcd2d..2396ffc 100644 --- a/examples/QuadrupedControl/QuadrupedHelper.h +++ b/examples/QuadrupedControl/QuadrupedHelper.h @@ -24,5 +24,8 @@ void doUSLeft(); void doUSScan(); #endif +void doCalibration(); + + #endif // _QUADRUPED_HELPER_H #pragma once diff --git a/examples/QuadrupedControl/QuadrupedServoConfiguration.h b/examples/QuadrupedControl/QuadrupedServoConfiguration.h index 72dec5e..68e184e 100644 --- a/examples/QuadrupedControl/QuadrupedServoConfiguration.h +++ b/examples/QuadrupedControl/QuadrupedServoConfiguration.h @@ -5,8 +5,8 @@ * Author: Armin */ -#ifndef QUADRUPED_SERVO_CONFIGURATION_H_ -#define QUADRUPED_SERVO_CONFIGURATION_H_ +#ifndef _QUADRUPED_SERVO_CONFIGURATION_H +#define _QUADRUPED_SERVO_CONFIGURATION_H /* * Leg layout geometry @@ -78,6 +78,5 @@ #define TROT_BASE_ANGLE_BL_FR 45 #define TROT_MOVE_ANGLE 30 -#endif /* QUADRUPED_SERVO_CONFIGURATION_H_ */ - +#endif // _QUADRUPED_SERVO_CONFIGURATION_H #pragma once diff --git a/examples/QuadrupedControl/QuadrupedServoControl.h b/examples/QuadrupedControl/QuadrupedServoControl.h index 78a5e08..5b3605e 100644 --- a/examples/QuadrupedControl/QuadrupedServoControl.h +++ b/examples/QuadrupedControl/QuadrupedServoControl.h @@ -5,8 +5,8 @@ * Author: Armin */ -#ifndef QUADRUPEDSERVOCONTROL_H_ -#define QUADRUPEDSERVOCONTROL_H_ +#ifndef _QUADRUPED_SERVO_CONTROL_H +#define _QUADRUPED_SERVO_CONTROL_H #include "QuadrupedServoConfiguration.h" @@ -93,5 +93,5 @@ void printAndSetTrimAngles(); void eepromReadAndSetServoTrim(); void eepromWriteServoTrim(); -#endif /* QUADRUPEDSERVOCONTROL_H_ */ +#endif // _QUADRUPED_SERVO_CONTROL_H #pragma once diff --git a/examples/QuadrupedControl/QuadrupedServoControl.hpp b/examples/QuadrupedControl/QuadrupedServoControl.hpp index e8aeeb3..fd5750f 100644 --- a/examples/QuadrupedControl/QuadrupedServoControl.hpp +++ b/examples/QuadrupedControl/QuadrupedServoControl.hpp @@ -26,11 +26,11 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ -#ifndef QUADRUPEDSERVOCONTROL_HPP -#define QUADRUPEDSERVOCONTROL_HPP +#ifndef _QUADRUPED_SERVO_CONTROL_HPP +#define _QUADRUPED_SERVO_CONTROL_HPP #include @@ -414,5 +414,5 @@ void synchronizeMoveAllServosAndCheckInputAndWait() { updateAndCheckInputAndWaitForAllServosToStop(); } -#endif /* QUADRUPEDSERVOCONTROL_HPP */ +#endif // _QUADRUPED_SERVO_CONTROL_HPP #pragma once diff --git a/examples/QuadrupedControl/UserCommands.cpp b/examples/QuadrupedControl/UserCommands.cpp index 733c4ed..b7f46e6 100644 --- a/examples/QuadrupedControl/UserCommands.cpp +++ b/examples/QuadrupedControl/UserCommands.cpp @@ -20,7 +20,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ /* @@ -92,7 +92,8 @@ #include "IRCommandDispatcher.h" #endif #if defined(QUADRUPED_ENABLE_RTTTL) -#include +//#define USE_NO_RTX_EXTENSIONS // Disables RTX format definitions `'s'` (style) and `'l'` (loop). Saves up to 332 bytes program memory +#include #endif #if defined(QUADRUPED_HAS_NEOPIXEL) #include "QuadrupedNeoPixel.h" diff --git a/examples/RobotArmControl/ADCUtils.cpp b/examples/RobotArmControl/ADCUtils.cpp index 557f233..c9c47a5 100644 --- a/examples/RobotArmControl/ADCUtils.cpp +++ b/examples/RobotArmControl/ADCUtils.cpp @@ -19,7 +19,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include "ADCUtils.h" diff --git a/examples/RobotArmControl/ADCUtils.h b/examples/RobotArmControl/ADCUtils.h index a1015c9..b0874fc 100644 --- a/examples/RobotArmControl/ADCUtils.h +++ b/examples/RobotArmControl/ADCUtils.h @@ -17,7 +17,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/examples/RobotArmControl/EasyButtonAtInt01.h b/examples/RobotArmControl/EasyButtonAtInt01.h index 5b0933e..5be4455 100644 --- a/examples/RobotArmControl/EasyButtonAtInt01.h +++ b/examples/RobotArmControl/EasyButtonAtInt01.h @@ -28,7 +28,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #ifndef _EASY_BUTTON_AT_INT01_H diff --git a/examples/RobotArmControl/EasyButtonAtInt01.hpp b/examples/RobotArmControl/EasyButtonAtInt01.hpp index b9d696e..1dab8ed 100644 --- a/examples/RobotArmControl/EasyButtonAtInt01.hpp +++ b/examples/RobotArmControl/EasyButtonAtInt01.hpp @@ -31,7 +31,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ /* diff --git a/examples/RobotArmControl/RobotArmControl.ino b/examples/RobotArmControl/RobotArmControl.ino index a2dd190..c934350 100644 --- a/examples/RobotArmControl/RobotArmControl.ino +++ b/examples/RobotArmControl/RobotArmControl.ino @@ -23,7 +23,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include diff --git a/examples/RobotArmControl/RobotArmIRCommands.cpp b/examples/RobotArmControl/RobotArmIRCommands.cpp index ec9fcf5..d5d9f37 100644 --- a/examples/RobotArmControl/RobotArmIRCommands.cpp +++ b/examples/RobotArmControl/RobotArmIRCommands.cpp @@ -22,7 +22,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include diff --git a/examples/RobotArmControl/RobotArmKinematics.cpp b/examples/RobotArmControl/RobotArmKinematics.cpp index fad59b1..e57b90c 100644 --- a/examples/RobotArmControl/RobotArmKinematics.cpp +++ b/examples/RobotArmControl/RobotArmKinematics.cpp @@ -20,7 +20,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include "RobotArmKinematics.h" diff --git a/examples/Simple/PinDefinitionsAndMore.h b/examples/Simple/PinDefinitionsAndMore.h index 62ade87..0e89623 100644 --- a/examples/Simple/PinDefinitionsAndMore.h +++ b/examples/Simple/PinDefinitionsAndMore.h @@ -20,7 +20,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/examples/Simple/Simple.ino b/examples/Simple/Simple.ino index f17cc62..fae85cc 100644 --- a/examples/Simple/Simple.ino +++ b/examples/Simple/Simple.ino @@ -20,7 +20,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include diff --git a/examples/SpeedTest/ADCUtils.cpp b/examples/SpeedTest/ADCUtils.cpp index 557f233..c9c47a5 100644 --- a/examples/SpeedTest/ADCUtils.cpp +++ b/examples/SpeedTest/ADCUtils.cpp @@ -19,7 +19,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include "ADCUtils.h" diff --git a/examples/SpeedTest/ADCUtils.h b/examples/SpeedTest/ADCUtils.h index a1015c9..b0874fc 100644 --- a/examples/SpeedTest/ADCUtils.h +++ b/examples/SpeedTest/ADCUtils.h @@ -17,7 +17,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/examples/SpeedTest/PinDefinitionsAndMore.h b/examples/SpeedTest/PinDefinitionsAndMore.h index 62ade87..0e89623 100644 --- a/examples/SpeedTest/PinDefinitionsAndMore.h +++ b/examples/SpeedTest/PinDefinitionsAndMore.h @@ -20,7 +20,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/examples/SpeedTest/SpeedTest.ino b/examples/SpeedTest/SpeedTest.ino index 6f51d50..40643ad 100644 --- a/examples/SpeedTest/SpeedTest.ino +++ b/examples/SpeedTest/SpeedTest.ino @@ -44,7 +44,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include diff --git a/examples/SymmetricEasing/PinDefinitionsAndMore.h b/examples/SymmetricEasing/PinDefinitionsAndMore.h index 62ade87..0e89623 100644 --- a/examples/SymmetricEasing/PinDefinitionsAndMore.h +++ b/examples/SymmetricEasing/PinDefinitionsAndMore.h @@ -20,7 +20,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/examples/SymmetricEasing/SymmetricEasing.ino b/examples/SymmetricEasing/SymmetricEasing.ino index fc64170..cdd0a64 100644 --- a/examples/SymmetricEasing/SymmetricEasing.ino +++ b/examples/SymmetricEasing/SymmetricEasing.ino @@ -19,7 +19,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include diff --git a/examples/ThreeServos/PinDefinitionsAndMore.h b/examples/ThreeServos/PinDefinitionsAndMore.h index 62ade87..0e89623 100644 --- a/examples/ThreeServos/PinDefinitionsAndMore.h +++ b/examples/ThreeServos/PinDefinitionsAndMore.h @@ -20,7 +20,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/examples/ThreeServos/ThreeServos.ino b/examples/ThreeServos/ThreeServos.ino index 943218a..cd4318a 100644 --- a/examples/ThreeServos/ThreeServos.ino +++ b/examples/ThreeServos/ThreeServos.ino @@ -19,7 +19,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include diff --git a/examples/TwoServos/PinDefinitionsAndMore.h b/examples/TwoServos/PinDefinitionsAndMore.h index 62ade87..0e89623 100644 --- a/examples/TwoServos/PinDefinitionsAndMore.h +++ b/examples/TwoServos/PinDefinitionsAndMore.h @@ -20,7 +20,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/examples/TwoServos/TwoServos.ino b/examples/TwoServos/TwoServos.ino index 53c2de6..e85f095 100644 --- a/examples/TwoServos/TwoServos.ino +++ b/examples/TwoServos/TwoServos.ino @@ -21,7 +21,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include diff --git a/src/LightweightServo.h b/src/LightweightServo.h index caaf116..ae8d9a9 100644 --- a/src/LightweightServo.h +++ b/src/LightweightServo.h @@ -17,7 +17,7 @@ * GNU General Public License for more details. * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/src/LightweightServo.hpp b/src/LightweightServo.hpp index 351828d..fe6853d 100644 --- a/src/LightweightServo.hpp +++ b/src/LightweightServo.hpp @@ -22,7 +22,7 @@ * GNU General Public License for more details. * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/src/ServoEasing.h b/src/ServoEasing.h index c77fb1e..81e4b88 100644 --- a/src/ServoEasing.h +++ b/src/ServoEasing.h @@ -17,7 +17,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . * */ diff --git a/src/ServoEasing.hpp b/src/ServoEasing.hpp index 7f912e4..a6552dd 100644 --- a/src/ServoEasing.hpp +++ b/src/ServoEasing.hpp @@ -25,7 +25,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ /*