Skip to content

Commit

Permalink
Merge pull request #4 from noshluk2/noshluk2/issue2
Browse files Browse the repository at this point in the history
  • Loading branch information
noshluk2 committed Apr 15, 2023
2 parents c044b9b + f089f38 commit b70fe1e
Show file tree
Hide file tree
Showing 6 changed files with 389 additions and 12 deletions.
Binary file added esp32_bot/meshes/ddr_bodyBase.stl
Binary file not shown.
Binary file added esp32_bot/meshes/ddr_bodyCover.stl
Binary file not shown.
138 changes: 138 additions & 0 deletions esp32_bot/src/bluetooth.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// #include <Arduino.h>
// #include "BluetoothSerial.h"

// #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
// #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
// #endif
// // motor pins
// #define motorRa 14
// #define motorRb 27
// #define motorLa 26
// #define motorLb 25
// #define Rpwm 12
// #define Lpwm 33

// //PWM setup
// const int channel_R = 0; //PWM setup
// const int channel_L = 1;
// void setup_motors();
// void process_input(String input);
// void go_backward(int pwm);
// void turn_right(int pwm);
// void turn_left(int pwm);
// void stop();
// void forward(int pwm);

// BluetoothSerial SerialBT;
// void setup()
// {
// Serial.begin(115200);
// SerialBT.begin("ESP32_BT");
// setup_motors();
// }

// void loop()
// {
// if (SerialBT.available()) {
// String input = SerialBT.readStringUntil('\n');
// Serial.println(input);
// process_input(input);
// }
// }

// void setup_motors(){
// // pwm setup variables
// const int freq = 5000;
// const int res = 8;

// // direction for motor pinout defination
// pinMode(motorLa, OUTPUT);
// pinMode(motorLb, OUTPUT);
// pinMode(motorRa, OUTPUT);
// pinMode(motorRb, OUTPUT);
// // Pwm functionality setup
// ledcSetup(channel_R ,freq , res);
// ledcSetup(channel_L ,freq , res);
// ledcAttachPin(Rpwm,channel_R);
// ledcAttachPin(Lpwm,channel_L);
// }



// void process_input(String input) {
// char command = input.charAt(0);
// int fixed_pwm = 150;

// if (command == 'r') {
// turn_right(fixed_pwm);
// } else if (command == 'f') {
// forward(fixed_pwm);
// }else if (command == 'l') {
// turn_left(fixed_pwm);
// } else if (command == 'b') {
// go_backward(fixed_pwm);
// }else if (command == 's') {
// stop();
// } else {
// Serial.println("Invalid input");
// }
// }

// void turn_right(int pwm) {
// // Left motor forward
// ledcWrite(channel_L, pwm);
// digitalWrite(motorLa, HIGH);
// digitalWrite(motorLb, LOW);

// // Right motor backward
// ledcWrite(channel_R, pwm);
// digitalWrite(motorRa, LOW);
// digitalWrite(motorRb, HIGH);
// }

// void turn_left(int pwm) {
// // Left motor backward
// ledcWrite(channel_L, pwm);
// digitalWrite(motorLa, LOW);
// digitalWrite(motorLb, HIGH);

// // Right motor forward
// ledcWrite(channel_R, pwm);
// digitalWrite(motorRa, HIGH);
// digitalWrite(motorRb, LOW);
// }

// void go_backward(int pwm) {
// // Left motor backward
// ledcWrite(channel_L, pwm);
// digitalWrite(motorLa, LOW);
// digitalWrite(motorLb, HIGH);

// // Right motor backward
// ledcWrite(channel_R, pwm);
// digitalWrite(motorRa, LOW);
// digitalWrite(motorRb, HIGH);
// }
// void stop(){
// // Left motor stop
// ledcWrite(channel_L, 0);
// digitalWrite(motorLa, LOW);
// digitalWrite(motorLb, LOW);

// // Right motor stop
// ledcWrite(channel_R, 0);
// digitalWrite(motorRa, LOW);
// digitalWrite(motorRb, LOW);
// }

// void forward(int pwm){
// // Left motor forward
// ledcWrite(channel_L, pwm);
// digitalWrite(motorLa, HIGH);
// digitalWrite(motorLb, LOW);

// // Right motor forward
// ledcWrite(channel_R, pwm);
// digitalWrite(motorRa, HIGH);
// digitalWrite(motorRb, LOW);
// }
77 changes: 65 additions & 12 deletions esp32_bot/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,72 @@
#include <Arduino.h>
#define LED_BUILTIN 2
void setup() {
// put your setup code here, to run once:

// motor pins
#define motorRa 27
#define motorRb 14
#define motorLa 25
#define motorLb 26
#define Rpwm 12
#define Lpwm 33

//PWM setup
const int channel_R = 0; //PWM setup
const int channel_L = 1;
void setup_motors();
void process_input(String input);
void run_motor_R(int pwm);
void run_motor_L(int pwm);
void setup()
{
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
setup_motors();
}

void loop()
{
if (Serial.available() > 0) {
String input = Serial.readStringUntil('\n');
process_input(input);
}
}

void setup_motors(){
// pwm setup variables
const int freq = 5000;
const int res = 8;

// direction for motor pinout defination
pinMode(motorLa, OUTPUT);
pinMode(motorLb, OUTPUT);
pinMode(motorRa, OUTPUT);
pinMode(motorRb, OUTPUT);
// Pwm functionality setup
ledcSetup(channel_R ,freq , res);
ledcSetup(channel_L ,freq , res);
ledcAttachPin(Rpwm,channel_R);
ledcAttachPin(Lpwm,channel_L);
}

void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
Serial.println("Hello World");
// put your main code here, to run repeatedly:
void process_input(String input) {
char motor = input.charAt(0);
int pwm = input.substring(1).toInt();

}
if (motor == 'r') {
run_motor_R(pwm);
} else if (motor == 'l') {
run_motor_L(pwm);
} else {
Serial.println("Invalid input");
}
}

void run_motor_R(int pwm) {
ledcWrite(channel_R, pwm);
digitalWrite(motorRa, HIGH);
digitalWrite(motorRb, LOW);
}

void run_motor_L(int pwm) {
ledcWrite(channel_L, pwm);
digitalWrite(motorLa, HIGH);
digitalWrite(motorLb, LOW);
}
72 changes: 72 additions & 0 deletions esp32_bot/src/test_motor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// #include <Arduino.h>

// // motor pins
// #define motorRa 27
// #define motorRb 14
// #define motorLa 25
// #define motorLb 26
// #define Rpwm 12
// #define Lpwm 33

// //PWM setup
// const int channel_R = 0; //PWM setup
// const int channel_L = 1;
// void setup_motors();
// void process_input(String input);
// void run_motor_R(int pwm);
// void run_motor_L(int pwm);
// void setup()
// {
// Serial.begin(115200);
// setup_motors();
// }

// void loop()
// {
// if (Serial.available() > 0) {
// String input = Serial.readStringUntil('\n');
// process_input(input);
// }
// }

// void setup_motors(){
// // pwm setup variables
// const int freq = 5000;
// const int res = 8;

// // direction for motor pinout defination
// pinMode(motorLa, OUTPUT);
// pinMode(motorLb, OUTPUT);
// pinMode(motorRa, OUTPUT);
// pinMode(motorRb, OUTPUT);
// // Pwm functionality setup
// ledcSetup(channel_R ,freq , res);
// ledcSetup(channel_L ,freq , res);
// ledcAttachPin(Rpwm,channel_R);
// ledcAttachPin(Lpwm,channel_L);
// }

// void process_input(String input) {
// char motor = input.charAt(0);
// int pwm = input.substring(1).toInt();

// if (motor == 'r') {
// run_motor_R(pwm);
// } else if (motor == 'l') {
// run_motor_L(pwm);
// } else {
// Serial.println("Invalid input");
// }
// }

// void run_motor_R(int pwm) {
// ledcWrite(channel_R, pwm);
// digitalWrite(motorRa, HIGH);
// digitalWrite(motorRb, LOW);
// }

// void run_motor_L(int pwm) {
// ledcWrite(channel_L, pwm);
// digitalWrite(motorLa, HIGH);
// digitalWrite(motorLb, LOW);
// }
Loading

0 comments on commit b70fe1e

Please sign in to comment.