You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[X] 90 deg bent transparent pvc tube (50mm inner dia) as the feeder right next to the wheels - 3x (need to cut one piece in order to act as connector between 2 50mm pipes)
[X] XT60 parallel connector - 2x (1M to 3F) (we need 5 female ports; 2x for main motors, 2x for future horizontal/vertical servos, 1x for ball selector servo)
ESP32 code for controlling the speed of continuous servo
Install the “ESP32 Servo” library (by Kevin et.al)
#include<ESP32Servo.h>Servog_feeder_servo;
intg_feeder_servo_pin=9; // change this as per your circuitvoidsetup() {
g_feeder_servo.attach(g_feeder_servo_pin);
// start with no rotation of the feeder servointspeed=map(0, -100, 100, 0, 180);
g_feeder_servo.write(speed);
}
voidloop() {
// int feeder_servo_speed = ...intspeed=map(feeder_servo_speed, -100, 100, 0, 180);
g_feeder_servo.write(speed)
}
ESP32 code for controlling the speed of BLDC motor via ESC
Install the “ESP32 Servo” library (by Kevin et.al)
Make sure to power using the BEC output of ESC
#include<ESP32Servo.h>Servog_left_servo;
Servog_right_servo;
intg_left_servo_pin=14; // change this as per your circuitintg_right_servo_pin=15; // change this as per your circuitvoidsetup() {
g_left_servo.attach(g_left_servo_pin);
g_right_servo.attach(g_right_servo_pin);
// start with no rotation of the main motorsintspeed=map(0, 0, 100, 0, 180);
g_left_servo.write(speed);
g_right_servo.write(speed);
}
voidloop() {
// int left_servo_speed = ...// int right_servo_speed = ...intlspeed=map(left_servo_speed, 0, 100, 0, 180);
g_left_servo.write(lspeed)
intrspeed=map(right_servo_speed, 0, 100, 0, 180);
g_right_servo.write(rspeed)
}
ESP32 code for bluetooth functionality
use “Serial Bluetooth Terminal” app on Play Store.
#include<BluetoothSerial.h>#include<ESP32Servo.h>// Check if Bluetooth configs are enabled#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to enable it
#endifclassMotor {
Servom_servo; // the servo objectintm_pin; // pin number on ESP32 where the wire is connected tointm_min; // minimum value (user visible) for the servo (angle or speed)intm_max; // maximum value (user visible)for the servopublic:
Motor(intpin, intmi, intma): m_servo(), m_pin(pin), m_min(mi), m_max(ma) {
}
voidset_value(longvalue) {
intservo_value=map(value, m_min, m_max, 0, 180);
m_servo.write(servo_value);
}
}; // class MotorenumServo_Index {
S_LEFT=0, // left main motorS_RIGHT, // right main motorS_FEEDER, // ball feeder servoS_HORIZONTAL, // horizontal rotation servoS_VERTICAL, // vertical rotation servoS_N_SERVOS,
S_LEFT_RIGHT, // need to change the speed of both left and right motors togetherS_RANDOM// change all the servo values randomly
}; // enum Servo_IndexstaticconstintMSGLEN=64;
// NOTE: update the GPIO pin value as per your circuit!Motorg_servos[S_N_SERVOS] = [
Motor(9, 0, 100),
Motor(10, 0, 100),
Motor(11, -100, 100),
Motor(12, 0, 100),
Motor(13, 0, 100)
];
BluetoothSerialg_BTS;
Stringg_message;
// parses an int inside the substring of a given String// eliminates the need for creating another String objectlongto_int(constString&in, longstart_pos, longend_pos) {
longret=0;
for (longi=start_pos; i<end_pos; ++i) {
charc=in.charAt(i);
if ('0' <= c&&c <= '9') {
ret=ret*10+c-'0';
} else {
return0;
}
}
returnret;
}
voidsetup() {
g_BTS.begin("Squash Ball Feeder");
g_message.reserve(STRLEN);
}
voidloop() {
if (g_BTS.available()) {
charin_char=g_BTS.read();
if (in_char!='\n') {
g_message+=String(in_char);
return;
}
}
if (g_message.length() <2) {
goto RETURN;
}
charfirst=g_message.charAt(0);
charsecond=g_message.charAt(1);
longvalue;
Servo_Indexs_idx;
intstart=1;
switch (first) {
case's':
if (second=='l') {
start=2;
s_idx=S_LEFT;
} elseif (second=='r') {
start=2;
s_idx=S_RIGHT;
} else {
s_idx=S_LEFT_RIGHT;
}
break;
case'f':
s_idx=S_FEEDER;
break;
case'h':
s_idx=S_HORIZONTAL;
break;
case'v':
s_idx=S_VERTICAL;
break;
case'r':
s_idx=S_RANDOM;
break;
default:
goto RETURN;
}
if (s_idx==S_RANDOM) {
// TODO
} else {
longvalue=to_int(g_message, start, g_message.length());
if (s_idx==S_LEFT_RIGHT) {
servos[S_LEFT].set_value(value);
servos[S_RIGHT].set_value(value);
} else {
servos[s_idx].set_value(value);
}
}
RETURN:
g_message.clear();
}
Servos - good for angles. Usually smaller than motors
Gears
Sprockets - larger teeth, bigger gap between the teeth
Shaft - to attach Motor/Servo or Gear/Sprocket to your machine
Cortex - the main controlling agent
Fasteners
screws to hold things together (usually black)
need a hex shaft to tighten/loosen the screw
screws fit well to most parts, except motor screws and collars
motor screws - to attach motors to things (usually gold)
collars - attach to drive shaft to hold things in place
Things to keep in mind
Steel and Aluminium based C-Channels. Steel is strong but heavy. Aluminium is light.
Try to avoid cutting the C-Channels (once cut, hard to rejoin!)
C-Channel lengths: 25 holes and 35 holes (aka full length)
Mount your C-Channels with Nylocks (avoid kegnuts which can become loose)
Use Axles of proper lengths
Keep the Axles in place using shaft collars
Ensure a bearing whenever there’s an Axle
Use spacers on Axles to position your wheels. Also prevents metal-metal contact. Spacers also come in different thicknesses. Make use of all of them when needed!