RBE1001Lib
FullSystemTest.ino
Go to the documentation of this file.
1 #include <RBE1001Lib.h>
2 #include "Motor.h"
3 #include "Rangefinder.h"
4 #include <ESP32Servo.h>
5 #include <ESP32AnalogRead.h>
6 // https://wpiroboticsengineering.github.io/RBE1001Lib/classMotor.html
9 // https://wpiroboticsengineering.github.io/RBE1001Lib/classRangefinder.html
11 // https://wpiroboticsengineering.github.io/RBE1001Lib/classServo.html
13 // https://wpiroboticsengineering.github.io/RBE1001Lib/classESP32AnalogRead.html
17 bool upDown = false;
18 /*
19  * This is the standard setup function that is called when the ESP32 is rebooted
20  * It is used to initialize anything that needs to be done once.
21  */
22 void setup()
23 {
24  // This will initialize the Serial as 115200 for prints
25  Serial.begin(115200);
26  // pin definitions https://wpiroboticsengineering.github.io/RBE1001Lib/RBE1001Lib_8h.html#define-members
28  lifter.attach(SERVO_PIN);
29  leftLineSensor.attach(LEFT_LINE_SENSE);
30  rightLineSensor.attach(RIGHT_LINE_SENSE);
31  servoPositionFeedback.attach(SERVO_FEEDBACK_SENSOR);
32 }
33 
34 /*
35  * The main loop for the program. The loop function is repeatedly called
36  * once the ESP32 is started.
37  */
38 void loop()
39 {
40  upDown = !upDown;
41  int loopTime = 4000; // 4 second loop
42  int servoRange = 180;
43 
44  right_motor.setSetpointWithSinusoidalInterpolation(upDown ? 360 : 0, loopTime);
45  left_motor.setSetpointWithLinearInterpolation(upDown ? 360 : 0, loopTime);
46 
47  for (int i = 0; i < servoRange; i++)
48  {
49  delay(loopTime / servoRange);
50  Serial.println("\n");
51  Serial.print("Range 1 " + String(rangefinder1.getDistanceCM()));
52  // Serial.print("Speed 1 "+String(left_motor.getDegreesPerSecond())+
53  // " Speed 2 "+String(right_motor.getDegreesPerSecond()));
54  Serial.print("\tCount 1 " + String(left_motor.getCurrentDegrees()) +
55  "\t Count 2 " + String(right_motor.getCurrentDegrees()));
56  Serial.print("\t Line left " + String(leftLineSensor.readVoltage()));
57 
58  Serial.print("\t Line right " + String(rightLineSensor.readVoltage()));
59  Serial.print("\t Servo Read " + String(servoPositionFeedback.readVoltage()));
60  Serial.print("\t Servo write " + String(i));
61  lifter.write(i);
62  }
63 }
#define SIDE_ULTRASONIC_ECHO
Definition: RBE1001Lib.h:25
float getDistanceCM()
get the distance of an object from the sensor in centimeters
void write(int value)
Definition: ESP32Servo.cpp:131
bool upDown
ESP32AnalogRead rightLineSensor
#define RIGHT_LINE_SENSE
Definition: RBE1001Lib.h:30
void setup()
ESP32AnalogRead leftLineSensor
void setSetpointWithLinearInterpolation(float newTargetInDegrees, long miliseconds)
Definition: Motor.h:380
#define LEFT_LINE_SENSE
Definition: RBE1001Lib.h:28
#define SERVO_FEEDBACK_SENSOR
Definition: RBE1001Lib.h:32
Rangefinder objects wrap a FreeRTOS thread with pin change interrupts to read trigger/echo style ultr...
Definition: Rangefinder.h:21
Servo lifter
LeftMotor left_motor
void loop()
float getCurrentDegrees()
Definition: Motor.cpp:568
ESP32AnalogRead servoPositionFeedback
Rangefinder rangefinder1
void attach(int pin)
void attach(int trigger, int echo)
Attach 2 pins to be used as triger and echo.
Definition: Rangefinder.cpp:92
RightMotor right_motor
#define SERVO_PIN
Definition: RBE1001Lib.h:36
int attach(int pin)
Definition: ESP32Servo.cpp:73
void setSetpointWithSinusoidalInterpolation(float newTargetInDegrees, long miliseconds)
Definition: Motor.h:396
#define SIDE_ULTRASONIC_TRIG
Definition: RBE1001Lib.h:24