Lab Guide: Cobot End-Effector Programming for Mushroom Bio-Factories
Objective: Program a 3-DOF Cobot’s end-effector to automate the handling of Orellana mushroom substrate and spore collection.
General Wokwi Setup:
Microcontroller: ESP32.
Servos: Connect VCC to 5V (Red), GND to GND (Black), and Signal to the assigned Pin (Orange).
Button: Connect one side to GND and the other to the assigned Pin.
Mission 1: The Substrate Shear (Sequential Logic)
Scenario: The cobot must perform a quick, forceful cut into the substrate blocks to prepare them for inoculation.
Task: Program a fast closing motion and a slow safety opening.
Wokwi Connection: Signal to Pin 18.
Servo shearServo;
const int shearPin = 18;
void setup() {
shearServo.attach(shearPin);
shearServo.write(0); // Initial position: Open
}
void loop() {
// --- STUDENT CHALLENGE ---
// 1. Move the servo to 130 degrees for a fast cut
shearServo.______(130);
// 2. Add a delay of 200ms to allow the blade to pass through
______(200);
// 3. Return the servo to 0 degrees
shearServo.write(0);
// 4. Wait 2 seconds before the next substrate block arrives
delay(2000);
}
Mission 2: The Inoculum Mixer (Iterative Logic - Loops)
Scenario: Mix the spores into the substrate gently using a sweeping motion.
Task: Use a
forloop to create a smooth "sweep" to avoid damaging the mycelium.Wokwi Connection: Signal to Pin 19.
#include <ESP32Servo.h>
Servo mixerServo;
const int mixerPin = 19;
void setup() {
mixerServo.attach(mixerPin);
}
void loop() {
// Forward sweep: from 45 to 135 degrees
for (int pos = 45; pos <= 135; pos++) {
mixerServo.write(pos);
delay(20);
}
// --- STUDENT CHALLENGE ---
// Complete the 'for' loop to return from 135 back to 45 degrees
for (int pos = ____; pos >= ____; pos____) {
mixerServo.write(pos);
delay(20);
}
}
Mission 3: The Nutrient Dispenser (Conditional Logic)
Scenario: Release water or nutrients into the substrate only when an operator triggers the system.
Task: Use an
ifstatement to activate the valve upon button press.Wokwi Connection: Servo Signal to Pin 21 | Button to Pin 12.
#include <ESP32Servo.h>
Servo valveServo;
const int buttonPin = 12;
void setup() {
valveServo.attach(21);
pinMode(buttonPin, INPUT_PULLUP); // Internal pull-up resistor
}
void loop() {
// --- STUDENT CHALLENGE ---
// Detect if the button is pressed (Remember: INPUT_PULLUP logic)
if (digitalRead(buttonPin) == ____) {
valveServo.write(90); // Open valve
delay(1500); // Dispensing time
valveServo.write(0); // Close valve
}
}
Mission 4: Vertical Spore Sampler (Functions & Precision)
Scenario: Collect spore samples from the substrate surface using a high-precision vertical descent.
Task: Organize your code using Functions. Move the servo degree-by-degree very slowly.
Wokwi Connection: Signal to Pin 5.
#include <ESP32Servo.h>
Servo samplerServo;
void setup() {
samplerServo.attach(5);
samplerServo.write(0); // Start at top position
}
void loop() {
// Call the custom functions
descendSlowly();
delay(1000); // Time for collection
ascendFast();
delay(5000);
}
// --- STUDENT CHALLENGE ---
void descendSlowly() {
// Use a loop to move from 0 to 100 degrees slowly
for (int i = 0; i <= 100; i++) {
samplerServo.write(____); // Use the iterator variable
delay(60); // Slow speed for precision
}
}
void ascendFast() {
// Move the servo back to 0 degrees instantly
samplerServo.write(____);
}
No hay comentarios:
Publicar un comentario