Skip to content

Commit

Permalink
Add using aliases to example
Browse files Browse the repository at this point in the history
  • Loading branch information
Frogbots4634 committed Jul 6, 2019
1 parent 8ec95e9 commit 01fb5a9
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 28 deletions.
55 changes: 34 additions & 21 deletions examples/ControllerScanner/ControllerScanner.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,29 @@
* SOFTWARE.
*/

#include <HiTechnicServo.h>
#include <HiTechnicDcMotorController.h>
#include <HiTechnicController.h>
#include <HiTechnicMotor.h>
#include <HiTechnicServoController.h>
#include <Wire.h>
#include "HiTechnicController.h"
#include "HiTechnicDcMotorController.h"
#include "HiTechnicMotor.h"
#include "HiTechnicServoController.h"
#include "HiTechnicServo.h"
#include "Wire.h"

using DaisyChainPosition = HiTechnicController::DaisyChainPosition;
using MotorPort = HiTechnicDcMotorController::MotorPort;
using RunMode = HiTechnicDcMotorController::RunMode;
using ZeroPowerBehavior = HiTechnicDcMotorController::ZeroPowerBehavior;
using Direction = HiTechnicMotor::Direction;
using ServoPort = HiTechnicServoController::ServoPort;

#define PRESCALAR 4
#define TWI_FREQ 37390L

/*
* ================================================================
* Begin user code
* ================================================================
*/

boolean somethingFound = false;

void setup()
Expand All @@ -45,17 +58,17 @@ void loop()
Serial.println("Probing I2C bus for HiTechnic controllers...");
somethingFound = false;

tryMotorController(HiTechnicController::DaisyChainPosition::FIRST);
tryMotorController(HiTechnicController::DaisyChainPosition::SECOND);
tryMotorController(HiTechnicController::DaisyChainPosition::THIRD);
tryMotorController(HiTechnicController::DaisyChainPosition::FOURTH);
tryMotorController(HiTechnicController::DaisyChainPosition::NONE);

tryServoController(HiTechnicController::DaisyChainPosition::FIRST);
tryServoController(HiTechnicController::DaisyChainPosition::SECOND);
tryServoController(HiTechnicController::DaisyChainPosition::THIRD);
tryServoController(HiTechnicController::DaisyChainPosition::FOURTH);
tryServoController(HiTechnicController::DaisyChainPosition::NONE);
tryMotorController(DaisyChainPosition::FIRST);
tryMotorController(DaisyChainPosition::SECOND);
tryMotorController(DaisyChainPosition::THIRD);
tryMotorController(DaisyChainPosition::FOURTH);
tryMotorController(DaisyChainPosition::NONE);

tryServoController(DaisyChainPosition::FIRST);
tryServoController(DaisyChainPosition::SECOND);
tryServoController(DaisyChainPosition::THIRD);
tryServoController(DaisyChainPosition::FOURTH);
tryServoController(DaisyChainPosition::NONE);

if(!somethingFound)
{
Expand All @@ -67,7 +80,7 @@ void loop()
delay(5000);
}

void tryMotorController(HiTechnicController::DaisyChainPosition pos)
void tryMotorController(DaisyChainPosition pos)
{
HiTechnicDcMotorController controller(pos);

Expand All @@ -80,7 +93,7 @@ void tryMotorController(HiTechnicController::DaisyChainPosition pos)
{
Serial.print("--> Motor controller at daisy chain address ");

if(pos == HiTechnicController::DaisyChainPosition::NONE)
if(pos == DaisyChainPosition::NONE)
{
Serial.println("NONE");
}
Expand All @@ -93,7 +106,7 @@ void tryMotorController(HiTechnicController::DaisyChainPosition pos)
}
}

void tryServoController(HiTechnicController::DaisyChainPosition pos)
void tryServoController(DaisyChainPosition pos)
{
HiTechnicServoController controller(pos);

Expand All @@ -106,7 +119,7 @@ void tryServoController(HiTechnicController::DaisyChainPosition pos)
{
Serial.print("--> Servo controller at daisy chain address ");

if(pos == HiTechnicController::DaisyChainPosition::NONE)
if(pos == DaisyChainPosition::NONE)
{
Serial.println("NONE");
}
Expand Down
13 changes: 13 additions & 0 deletions examples/EmptyTemplate/EmptyTemplate.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,22 @@
#include "HiTechnicServo.h"
#include "Wire.h"

using DaisyChainPosition = HiTechnicController::DaisyChainPosition;
using MotorPort = HiTechnicDcMotorController::MotorPort;
using RunMode = HiTechnicDcMotorController::RunMode;
using ZeroPowerBehavior = HiTechnicDcMotorController::ZeroPowerBehavior;
using Direction = HiTechnicMotor::Direction;
using ServoPort = HiTechnicServoController::ServoPort;

#define PRESCALAR 4
#define TWI_FREQ 37390L

/*
* ================================================================
* Begin user code
* ================================================================
*/

void setup()
{
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,24 @@
#include "Wire.h"
#include "RollingIntegerAverage.h"

using DaisyChainPosition = HiTechnicController::DaisyChainPosition;
using MotorPort = HiTechnicDcMotorController::MotorPort;
using RunMode = HiTechnicDcMotorController::RunMode;
using ZeroPowerBehavior = HiTechnicDcMotorController::ZeroPowerBehavior;
using Direction = HiTechnicMotor::Direction;
using ServoPort = HiTechnicServoController::ServoPort;

#define PRESCALAR 4
#define TWI_FREQ 37390L

HiTechnicDcMotorController mc1(HiTechnicController::DaisyChainPosition::FIRST);
HiTechnicMotor someMotor(&mc1, HiTechnicDcMotorController::MotorPort::PORT_1);
/*
* ================================================================
* Begin user code
* ================================================================
*/

HiTechnicDcMotorController mc1(DaisyChainPosition::FIRST);
HiTechnicMotor someMotor(&mc1, MotorPort::PORT_1);

RollingIntegerAverage rollingAvg(5);

Expand All @@ -44,9 +57,9 @@ void setup()

Wire.begin(); //join the i2c bus

someMotor.setRunMode(HiTechnicDcMotorController::RunMode::STOP_AND_RESET_ENCODER);
someMotor.setZeroPowerBehavior(HiTechnicDcMotorController::ZeroPowerBehavior::BRAKE);
someMotor.setDirection(HiTechnicMotor::Direction::REVERSE);
someMotor.setMode(RunMode::STOP_AND_RESET_ENCODER);
someMotor.setZeroPowerBehavior(ZeroPowerBehavior::BRAKE);
someMotor.setDirection(Direction::REVERSE);
someMotor.setPower(0);
someMotor.getController()->setTimeoutEnabled(true);

Expand All @@ -56,7 +69,7 @@ void setup()

void loop()
{
someMotor.setRunMode(HiTechnicDcMotorController::RunMode::RUN_WITHOUT_ENCODER);
someMotor.setMode(RunMode::RUN_WITHOUT_ENCODER);
delay(500);

Serial.println("Open loop");
Expand All @@ -75,7 +88,7 @@ void loop()
rollingAvg.reset();
logZero(50);
delay(1000);
someMotor.setRunMode(HiTechnicDcMotorController::RunMode::RUN_USING_ENCODER);
someMotor.setMode(RunMode::RUN_USING_ENCODER);

Serial.println("Closed loop");

Expand Down

0 comments on commit 01fb5a9

Please sign in to comment.