Skip to content

Motor experimental changes #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@
*.exe
*.out
*.app
.vscode/c_cpp_properties.json
.vscode/settings.json
44 changes: 44 additions & 0 deletions examples/MotorSpeedTest/MotorSpeedTest.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <Arduino.h>
#include <RBE1001Lib.h>

Motor left_motor;
Motor right_motor;
bool upDown=false;
/*
* This is the standard setup function that is called when the ESP32 is rebooted
* It is used to initialize anything that needs to be done once.
*/
void setup() {
// This will initialize the Serial as 115200 for prints
Serial.begin(115200);
Motor::allocateTimer(0);
// pin definitions https://wpiroboticsengineering.github.io/RBE1001Lib/RBE1001Lib_8h.html#define-members
left_motor.attach(MOTOR_LEFT_PWM, MOTOR_LEFT_DIR, MOTOR_LEFT_ENCA, MOTOR_LEFT_ENCB);
right_motor.attach(MOTOR_RIGHT_PWM, MOTOR_RIGHT_DIR, MOTOR_RIGHT_ENCA, MOTOR_RIGHT_ENCB);
}


/*
* The main loop for the program. The loop function is repeatedly called
* once the ESP32 is started.
*/
void loop()
{
float speed = 360 * sin(2*3.14*(millis()%10000)/10000.);
left_motor.setSpeed(speed);
right_motor.setSpeed(speed);

Serial.print("SP: ");
Serial.print(speed);
Serial.print('\t');

Serial.print("L: ");
Serial.print(left_motor.getDegreesPerSecond());
Serial.print('\t');

Serial.print("R: ");
Serial.print(right_motor.getDegreesPerSecond());
Serial.print('\n');

delay(100);
}
111 changes: 81 additions & 30 deletions examples/MotorTest/MotorTest.ino
Original file line number Diff line number Diff line change
@@ -1,53 +1,104 @@
/*
* This program will wait for the button to be pressed and then:
* command the left motor to spin at 60 rpm,
* wait 5 seconds,
* and then stop the motor.
* While the motor is spinning, the program will print out how much it has turned (in degrees).
*/

#include <Arduino.h>
#include <Esp32WifiManager.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <RBE1001Lib.h>

Motor motor1;
Motor motor2;
bool upDown=false;
// pin definitions https://wpiroboticsengineering.github.io/RBE1001Lib/RBE1001Lib_8h.html#define-members
const int buttonPin = BOOT_FLAG_PIN ;

/*
* This is the standard setup function that is called when the ESP32 is rebooted
* It is used to initialize anything that needs to be done once.
*/
void setup() {
void setup()
{
// This will initialize the Serial as 115200 for prints
Serial.begin(115200);
Motor::allocateTimer(0);
// pin definitions https://wpiroboticsengineering.github.io/RBE1001Lib/RBE1001Lib_8h.html#define-members
motor1.attach(MOTOR1_PWM, MOTOR1_DIR, MOTOR1_ENCA, MOTOR1_ENCB);
motor2.attach(MOTOR2_PWM, MOTOR2_DIR, MOTOR2_ENCA, MOTOR2_ENCB);
//explicitly make the button pin an input and engage the internal pullup resistor
pinMode(buttonPin, INPUT_PULLUP);
}


/*
* The main loop for the program. The loop function is repeatedly called
* once the ESP32 is started.
*/
void loop() {
upDown=!upDown;
motor1.SetSetpointWithLinearInterpolation(upDown?3600:0, 8000);
//motor2.SetSetpointWithLinearInterpolation(upDown?360:0, 2000);
//motor2.SetSetpointWithBezierInterpolation(upDown?3600:0, 8000,0.45,1);
motor2.SetSetpointWithTrapezoidalInterpolation(upDown?3600:0, 8000, 500);
double peak1 = 0;
double peak2 =0;

for(int i=0;i<400;i++){
if(abs(motor1.getDegreesPerSecond())>peak1){
peak1=abs(motor1.getDegreesPerSecond());
}
if(abs(motor2.getDegreesPerSecond())>peak2){
peak2=abs(motor2.getDegreesPerSecond());
}
delay(20);
Serial.println("motor compared "+String(motor2.getInterpolationUnitIncrement()-motor1.getInterpolationUnitIncrement())+
+" Interp "+String(motor2.getInterpolationUnitIncrement())+
+" Vel 1 "+String(motor1.getDegreesPerSecond())+" Vel 2 "+String(motor2.getDegreesPerSecond()));
}
delay(100);
Serial.println("Count 1 "+String(motor1.getCurrentDegrees())+
" Count 2 "+String(motor2.getCurrentDegrees()));
delay(5000);


}
void loop()
{
//The following line will cause the program to wait indefinitely until the button is pressed
while(digitalRead(buttonPin)) {}

Serial.println("Setting speeds");

motor1.SetSpeed(180);
motor2.SetSpeed(-180);

uint32_t startTime = millis(); //note when the motor started


while(millis() - startTime < 3000) //run for 3 seconds
{
Serial.print(motor1.getCurrentDegrees()); //motor1 position
Serial.print('\t'); //TAB character
Serial.print(motor2.getCurrentDegrees()); //motor2 position
Serial.print('\n'); //newline character
}

// stop the motor
motor1.SetSpeed(0);
motor2.SetSpeed(0);

//The following line will cause the program to wait indefinitely until the button is pressed
while(digitalRead(buttonPin)) {}

motor1.SetEffort(0.35);
motor2.SetEffort(-0.25);

startTime = millis(); //note when the motor started

while(millis() - startTime < 3000) //run for 3 seconds
{
Serial.print(motor1.getCurrentDegrees()); //motor1 position
Serial.print('\t'); //TAB character
Serial.print(motor2.getCurrentDegrees()); //motor2 position
Serial.print('\n'); //newline character
}

// stop the motor
motor1.SetEffort(0);
motor2.SetEffort(0);

//The following line will cause the program to wait indefinitely until the button is pressed
while(digitalRead(buttonPin)) {}
motor1.StartMoveFor(720, -540);
motor2.MoveFor(-720, 540);

//The following line will cause the program to wait indefinitely until the button is pressed
while(digitalRead(buttonPin)) {}

motor1.StartMoveTo(0, -180);
motor2.MoveTo(0, 180);

while(digitalRead(buttonPin)) //run for 3 seconds
{
Serial.print(motor1.getCurrentDegrees()); //motor1 position
Serial.print('\t'); //TAB character
Serial.print(motor2.getCurrentDegrees()); //motor2 position
Serial.print('\n'); //newline character
}
}
1 change: 0 additions & 1 deletion examples/RCCTL/RCCTL.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ WebPage buttonPage;

WifiManager manager;


Timer dashboardUpdateTimer; // times when the dashboard should update
/*
* This is the standard setup function that is called when the ESP32 is rebooted
Expand Down
4 changes: 3 additions & 1 deletion examples/week01/button/button.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// pin definitions https://wpiroboticsengineering.github.io/RBE1001Lib/RBE1001Lib_8h.html#define-members
#include <RBE1001Lib.h>

// pin definitions https://wpiroboticsengineering.github.io/RBE1001Lib/RBE1001Lib_8h.html#define-members
const int buttonPin = BOOT_FLAG_PIN; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin

Expand Down
Loading