machining docs start

This commit is contained in:
2025-04-21 22:22:43 +02:00
parent f0744a5ec0
commit 3bd7a07563
4 changed files with 318 additions and 11 deletions

View File

@@ -275,6 +275,8 @@ They should be the same on each board you wanna communicate with. The only flaw
The reason this can be done without low overhead is because some ESP models have hardware encryption accelerators build in for AES-128. and that's also the encryption what is used in this ESPNow protocol when enabled. The reason this can be done without low overhead is because some ESP models have hardware encryption accelerators build in for AES-128. and that's also the encryption what is used in this ESPNow protocol when enabled.
![alt text](image-17.jpg)
## Charging my new batteries ## Charging my new batteries
This week I got my Li-Po batteries delivered. This week I got my Li-Po batteries delivered.

View File

@@ -0,0 +1,3 @@
# Lecture notes
`

View File

@@ -0,0 +1,288 @@
# Machine building week
For this week we needed to build a machine. We started brainstorming and came up with a few ideas.
## Custom boards
<!--add stuff about funny no esp in esp xiao and about using arduino with hat so we only had I2C-->
Quick multiplexer breakout board design for rapid prototyping.
![alt text](image.png)
When I tried connecting it into my breadboard the power connectors snapped loose because the breadboard was too stiff. So I didn't test the board and went straight to a next prototype.
![alt text](image-1.png)
With this board I wanted to make a breakout for 5 I2C devices. So I could hook up 5 time of flight sensors for example. The first attempt I gave up. I also asked henk for some feedback on how to do the connectors. He recommended using UDPI connectors and making breakout boards for every ToF sensor so I could connect them properly.
![alt text](image-3.png)
So my schematic wen't to this.
![alt text](image-2.png)
make because of all the bridges I needed to add in
![alt text](image-7.png)
This is the most recent design for now. It was a pain to make all the bridges and swapping back and forth.
This is the design for the breakout board. We are using pin headers since we already have soldered ToF sensors
![alt text](image-5.png)
![alt text](image-6.png)
![alt text](image-4.png)
## Chapter 2 Ultrasonic sensors
We didn't have enough ToF sensors for our robot. I asked Henk if I could order some for myself and use them in the project. But he told me no and to use ultrasonic sensors. And he told me to use the current board for that. But I said that wouldn't work because only one multiplexer pin goes to each breakout because I designed it for the ToF so now im going to do some solder hacking and try to wire it together myself.
??? Failure
```cpp
int readUltrasonicSensor(int trig, int echo)
{
long duration, cm;
// The sensor is triggered by a HIGH pulse of 10 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
ioex.write(PCA95x5::Port::P06, PCA95x5::Level::L);
delayMicroseconds(5);
ioex.write(PCA95x5::Port::P06, PCA95x5::Level::H);
delayMicroseconds(10);
ioex.write(PCA95x5::Port::P06, PCA95x5::Level::L);
ioex.direction(PCA95x5::Port::P07, PCA95x5::Direction::IN);
duration = pulseIn(ioex.read(PCA95x5::Port::P07), HIGH);
// Convert the time into a distance
cm = (duration / 2) / 29.1; // Divide by 29.1 or multiply by 0.0343
Serial.print("Distance: ");
Serial.print(cm);
return (cm);
// https://randomnerdtutorials.com/complete-guide-for-ultrasonic-sensor-hc-sr04/
}
```
Here I tried measuring the signal myself but I didn't receive anything back from the multiplexer
??? Failure
```cpp
// A0 trigger, A1 Echo
int readUltrasonicSensor(int trig, int echo)
{
long duration, cm;
// The sensor is triggered by a HIGH pulse of 10 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
ioex.write(PCA95x5::Port::P06, PCA95x5::Level::L);
delayMicroseconds(5);
ioex.write(PCA95x5::Port::P06, PCA95x5::Level::H);
delayMicroseconds(10);
long startTime = micros();
ioex.write(PCA95x5::Port::P06, PCA95x5::Level::L);
while (PCA95x5::Level::H == ioex.read(PCA95x5::Port::P07))
{
duration = micros() - startTime;
}
// Convert the time into a distance
cm = (duration / 2) / 29.1; // Divide by 29.1 or multiply by 0.0343
Serial.print("Distance: ");
Serial.print(cm);
return (cm);
// https://randomnerdtutorials.com/complete-guide-for-ultrasonic-sensor-hc-sr04/
}
```
Sort of works but it works super innacurate. I can move it around and it will display different values depending on how far it is from the table
![alt text](image-8.png)
For now I will plug the trigger into the multiplexer and the Echo pin into the arduino. Then I can measure the length of the signal to measure the distance.
### Optimization
We had the issue that the arduino didn't run fast enough to read from the sensors and to control the motors simultaneously even when shrinking down the code to this.
??? Old code
```cpp
#include <AccelStepper.h>
//=============================================================================================//
//Stepper motor pins
//=============================================================================================//
#define MOTOR_X_ENABLE_PIN 8
#define MOTOR_X_STEP_PIN 2
#define MOTOR_X_DIR_PIN 5
#define MOTOR_Y_ENABLE_PIN 8
#define MOTOR_Y_STEP_PIN 3
#define MOTOR_Y_DIR_PIN 6
#define MOTOR_Z_ENABLE_PIN 8
#define MOTOR_Z_STEP_PIN 4
#define MOTOR_Z_DIR_PIN 7
#define MOTOR_A_ENABLE_PIN 8
#define MOTOR_A_STEP_PIN 12
#define MOTOR_A_DIR_PIN 13
//=============================================================================================//
//Global object creations
//=============================================================================================//
AccelStepper motorX(1, MOTOR_X_STEP_PIN, MOTOR_X_DIR_PIN);
AccelStepper motorY(1, MOTOR_Y_STEP_PIN, MOTOR_Y_DIR_PIN);
AccelStepper motorZ(1, MOTOR_Z_STEP_PIN, MOTOR_Z_DIR_PIN);
AccelStepper motorA(1, MOTOR_A_STEP_PIN, MOTOR_A_DIR_PIN);
//=============================================================================================//
// Function declarations
//=============================================================================================//
void moveForw(int speed);
void moveBack(int speed);
void moveStop();
int readUltrasonicSensor(int trigPin, int echoPin);
void rotateLeft();
void stepperSetup();
int mm = 0;
void setup()
{
Serial.begin(9600);
stepperSetup();
pinMode(A2, INPUT);
}
void loop()
{
mm = readUltrasonicSensor(A1, A0) * 10; // Convert cm to mm
Serial.println(mm); // Print distance in mm
// Define distance thresholds
const int SAFE_DISTANCE_FRONT = 2500; // 500mm
const int WARNING_DISTANCE_FRONT = 1250; // 250mm
const int DANGER_DISTANCE_FRONT = 800; // 100mm
const int SAFE_DISTANCE_BACK = 400; // 40cm
const int DANGER_DISTANCE_BACK = 200; // 20cm
moveForw(0);
}
void moveForw(int stepDelay)
{
motorX.move(3000);
motorX.run();
motorY.move(3000);
motorY.run();
motorZ.move(3000);
motorZ.run();
motorA.move(3000);
motorA.run();
}
void moveBack(int speed)
{
motorX.move(-3000);
motorX.run();
motorY.move(-3000);
motorY.run();
motorZ.move(-3000);
motorZ.run();
motorA.move(-3000);
motorA.run();
}
void moveStop()
{
motorX.move(0);
motorX.run();
motorY.move(0);
motorY.run();
motorZ.move(0);
motorZ.run();
motorA.move(0);
motorA.run();
}
void rotateLeft()
{
motorX.move(3000);
motorX.run();
motorY.move(1500);
motorY.run();
motorZ.move(1500);
motorZ.run();
motorA.move(1500);
motorA.run();
}
// A0 trigger, A1 Echo
int readUltrasonicSensor(int trigPin, int echoPin) {
int duration, cm;
// The sensor is triggered by a HIGH pulse of 10 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the signal from the sensor: a HIGH pulse whose
// duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
// Convert the time into a distance
cm = (duration/2) / 29.1; // Divide by 29.1 or multiply by 0.0343
return cm;
}
void stepperSetup(){
pinMode(MOTOR_X_ENABLE_PIN, OUTPUT);
pinMode(MOTOR_Y_ENABLE_PIN, OUTPUT);
pinMode(MOTOR_Z_ENABLE_PIN, OUTPUT);
pinMode(MOTOR_A_ENABLE_PIN, OUTPUT);
motorX.setEnablePin(MOTOR_X_ENABLE_PIN);
motorX.setPinsInverted(false, false, true);
motorX.setAcceleration(100);
motorX.setMaxSpeed(100);
motorX.setSpeed(100);
motorX.enableOutputs();
motorY.setEnablePin(MOTOR_Y_ENABLE_PIN);
motorY.setPinsInverted(false, false, true);
motorY.setAcceleration(100);
motorY.setMaxSpeed(100);
motorY.setSpeed(100);
motorY.enableOutputs();
motorZ.setEnablePin(MOTOR_Z_ENABLE_PIN);
motorZ.setPinsInverted(false, false, true);
motorZ.setAcceleration(100);
motorZ.setMaxSpeed(100);
motorZ.setSpeed(100);
motorZ.enableOutputs();
motorA.setEnablePin(MOTOR_Z_ENABLE_PIN);
motorA.setPinsInverted(false, false, true);
motorA.setAcceleration(100);
motorA.setMaxSpeed(100);
motorA.setSpeed(100);
motorA.enableOutputs();
}
```
Issue: The motors didn't have enough power
Solution find the maximum current for the motors and the stepsticks in the datasheet.

View File

@@ -8,6 +8,7 @@ int mapPot(int normalizedValue);
int analogReadMultiPlexer(int addressA, int addressB, int addressC, int addressD, int pin); int analogReadMultiPlexer(int addressA, int addressB, int addressC, int addressD, int pin);
void espNow(); void espNow();
void readAllMultiPlexer(); void readAllMultiPlexer();
void espNowLoop();
const int MAXPWMVALUE = 1000; const int MAXPWMVALUE = 1000;
const int MINPWMVALUE = 2000; const int MINPWMVALUE = 2000;
@@ -40,31 +41,31 @@ void setup()
void loop() void loop()
{ {
readAllMultiPlexer();
// Set values to send // Set values to send
JoystickData.PWMCH1 = mapPot(analogReadMultiPlexer(0, 0, 0, 0, A0)); //Right joystick Y JoystickData.PWMCH1 = mapPot(analogReadMultiPlexer(0, 0, 0, 0, A0)); //Right joystick Y
JoystickData.PWMCH2 = mapPot(analogReadMultiPlexer(1, 0, 0, 0, A0)); // Right joystick X JoystickData.PWMCH2 = mapPot(analogReadMultiPlexer(1, 0, 0, 0, A0)); // Right joystick X
JoystickData.PWMCH3 = mapPot(analogReadMultiPlexer(0, 0, 0, 1, A0)); // left joystick Y JoystickData.PWMCH3 = mapPot(analogReadMultiPlexer(0, 0, 0, 1, A0)); // left joystick Y
JoystickData.PWMCH4 = mapPot(analogReadMultiPlexer(1, 0, 0, 1, A0)); // left joystick X JoystickData.PWMCH4 = mapPot(analogReadMultiPlexer(1, 0, 0, 1, A0)); // left joystick X
Serial.print("PWMCH1: ");
Serial.println(JoystickData.PWMCH1);
Serial.print(" PWMCH2: ");
Serial.println(JoystickData.PWMCH2);
Serial.print(" PWMCH3: ");
Serial.println(JoystickData.PWMCH3);
Serial.print(" PWMCH4: ");
Serial.println(JoystickData.PWMCH4);
// Send message via ESP-NOW espNowLoop();
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *)&JoystickData, sizeof(JoystickData));
if (result == ESP_OK)
{
// Serial.println("Sent with success");
}
else
{
// Serial.println("Error sending the data");
}
delay(10); // delay to avoid hammering the radio and to save power/heat delay(10); // delay to avoid hammering the radio and to save power/heat
} }
int mapPot(int normalizedValue) int mapPot(int normalizedValue)
{ {
return map(normalizedValue, 400, 2500, MINPWMVALUE, MAXPWMVALUE); // map the normalized value to the PWM range return map(normalizedValue, 400, 2500, MINPWMVALUE, MAXPWMVALUE); // map the normalized value to the PWM range
} }
//legacy stuff for original potsliders
int normalizePot(int pin, int minValue) // normalize the pot value to a range of 80 to 4095 instead of 0 to 4095 because the potmeter is at lower values not accurate int normalizePot(int pin, int minValue) // normalize the pot value to a range of 80 to 4095 instead of 0 to 4095 because the potmeter is at lower values not accurate
{ {
int pot = analogRead(pin); int pot = analogRead(pin);
@@ -145,4 +146,17 @@ void readAllMultiPlexer()
Serial.println(analogReadMultiPlexer(0, 1, 1, 1, A0)); Serial.println(analogReadMultiPlexer(0, 1, 1, 1, A0));
Serial.print("1,1,1,1: "); Serial.print("1,1,1,1: ");
Serial.println(analogReadMultiPlexer(1, 1, 1, 1, A0)); Serial.println(analogReadMultiPlexer(1, 1, 1, 1, A0));
}
void espNowLoop(){
// Send message via ESP-NOW
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *)&JoystickData, sizeof(JoystickData));
if (result == ESP_OK)
{
// Serial.println("Sent with success");
}
else
{
// Serial.println("Error sending the data");
}
} }