Skip to content
Draft
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
1 change: 1 addition & 0 deletions arduino_firmware/end_effector/CAN_FD_bridge.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <CAN_FD_bridge.h>
10 changes: 10 additions & 0 deletions arduino_firmware/end_effector/CAN_FD_bridge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef CAN_FD_BRIDGE_H
#define CAN_FD_BRIDGE_H

// Reconstructs CAN FD frame from an SPI message
void SPI_to_CAN_FD();

// Sends a CAN FD frame via an SPI message
void CAN_FD_to_SPI();

#endif CAN_FD_BRIDGE_H
16 changes: 16 additions & 0 deletions arduino_firmware/end_effector/end_effector_actions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <end_effector_actions.h>

// Interprets an SPI message and sends the corresponding action to the appropriate sensor
void handle_SPI_msg(uint8_t spi_peripheral_rx_buf[BUF_SIZE]) {
return void;
}

// Interprets a CAN FD message and sends the corresponding action over SPI if permissible
void handle_CAN_FD_message(uint8_t spi_controller_tx_buf[BUF_SIZE]) {
return void;
}

// Retrieves data from a requested sensor and sends it over SPI
void send_data_update_SPI_msg(uint8_t spi_peripheral_rx_buf[BUF_SIZE], uint8_t spi_peripheral_tx_buf[BUF_SIZE]) {
return void;
}
21 changes: 21 additions & 0 deletions arduino_firmware/end_effector/end_effector_actions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef END_EFFECTOR_ACTIONS_H
#define END_EFFECTOR_ACTIONS_H

#include <end_effector_base.h>

/* SPI message struct
- destination sensor
- sensor request
- sensor value
*/

// Interprets an SPI message and sends the corresponding action to the appropriate sensor or as a message over CAN FD if permissible
void handle_SPI_msg(uint8_t spi_peripheral_rx_buf[BUF_SIZE]);

// Interprets a CAN FD message and sends the corresponding action over SPI if permissible
void handle_CAN_FD_message(uint8_t spi_controller_tx_buf[BUF_SIZE]);

// Retrieves data from a requested sensor and sends it over SPI
void send_data_update_SPI_msg(uint8_t spi_peripheral_rx_buf[BUF_SIZE], uint8_t spi_peripheral_tx_buf[BUF_SIZE]);

#endif END_EFFECTOR_ACTIONS_H
7 changes: 7 additions & 0 deletions arduino_firmware/end_effector/end_effector_base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef END_EFFECTOR_BASE_H
#define END_EFFECTOR_BASE_H

// Standard data buffer size = 32 Bytes
static const uint16_t BUF_SIZE = 32;

#endif END_EFFECTOR_BASE_H
62 changes: 62 additions & 0 deletions arduino_firmware/end_effector/end_effector_big_gripper.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <end_effector_base.h>
#include <ESP32SPISlave.h>

// This ESP is the peripheral, the bridge ESP is the controller
ESP32SPISlave peripheral;

// Sending data buffer
uint8_t spi_peripheral_tx_buf[BUF_SIZE] = {0};

// Receiving data buffer
uint8_t spi_peripheral_rx_buf[BUF_SIZE] = {0};

void setup() {

Serial.begin(115200);

// Pin assignments can be customized
// Default pins are: VSPI (MISO=19, MOSI=23, SCLK=18, SS=5)
peripheral.begin(); // Uses default VSPI pins

// Set up buffers
peripheral.set_buffers(spi_peripheral_tx_buf, spi_peripheral_rx_buf, BUF_SIZE);

Serial.println("Big Gripper: SPI Peripheral Initialized");

}

void loop() {

// While no message has been recieved from the controller
while (!peripheral.wait(portMAX_DELAY)) {
;
}

// Once a message has been received from the controller
// Get the message size
size_t msg_size = peripheral.get_received_trans_len();

// Print the number of bytes received
Serial.print("Big Gripper: Received ");
Serial.print(msg_size);
Serial.print(" bytes: ");

// Print the msg
for (uint16_t i = 0; i < msg_size; i++) {
Serial.print(spi_peripheral_rx_buf[i], HEX);
// Clear the buffer
spi_peripheral_rx_buf[i] = 0;
}
Serial.println();

// Interpret the message and perform appropriate action
handle_SPI_msg(spi_peripheral_rx_buf);

// Get updated sensor values and send to the bridge module
// The controller will only pick this message up on the next message that it delivers
send_data_update_SPI_msg(spi_peripheral_rx_buf, spi_peripheral_tx_buf);

// Clear message status
peripheral.pop();

}
67 changes: 67 additions & 0 deletions arduino_firmware/end_effector/end_effector_bridge.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <CAN_FD_bridge.h>
#include <SPI.h>
#include <end_effector_base.h>

// Defines pin that peripheral ESP is connected to
#define SS_PIN 6

// Sending data buffer
uint8_t spi_controller_tx_buf[BUF_SIZE] = {0};

// Receiving data buffer
uint8_t spi_controller_rx_buf[BUF_SIZE] = {0};

void setup() {

Serial.begin(115200);

// Initialize SPI bus
SPI.begin();

// Set peripheral SS pin as inactive output (active-low)
pinMode(SS_PIN, OUTPUT);
digitalWrite(SS_PIN, HIGH);


Serial.println("Bridge ESP: SPI Controller Initialized");

}

void loop() {

// Translate CAN FD frame to SPI frame to send
handle_CAN_FD_message(spi_controller_tx_buf);

// Activate peripheral ESP connection for writing
digitalWrite(SS_PIN, LOW);

// Settings: 1MHz, Most significant bit first, data mode
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));

// Send all 32 bytes from buffer to the peripheral
for (int i = 0; i < BUF_SIZE; i++) {
// This sends a byte and receives a byte at the same time
spi_controller_rx_buf[i] = SPI.transfer(spi_controller_tx_buf[i]);
}

// Stop transmission
SPI.endTransaction();

// Deactivate peripheral connection
digitalWrite(SS_PIN, HIGH);

// Forward response message from peripheral onto CAN FD connection to Jetson
handle_SPI_msg(spi_controller_rx_buf);

// Print data received from peripheral
Serial.print("Bridge ESP: Received bytes: ");
for (int i = 0; i < BUF_SIZE; i++) {
Serial.print(spi_controller_rx_buf[i], HEX);
Serial.print(" ");
}
Serial.println();

// Delay before writing to peripheral again
delay(1000);

}
62 changes: 62 additions & 0 deletions arduino_firmware/end_effector/end_effector_core_xy.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <end_effector_base.h>
#include <ESP32SPISlave.h>

// This ESP is the peripheral, the bridge ESP is the controller
ESP32SPISlave peripheral;

// Sending data buffer
uint8_t spi_peripheral_tx_buf[BUF_SIZE] = {0};

// Receiving data buffer
uint8_t spi_peripheral_rx_buf[BUF_SIZE] = {0};

void setup() {

Serial.begin(115200);

// Pin assignments can be customized
// Default pins are: VSPI (MISO=19, MOSI=23, SCLK=18, SS=5)
peripheral.begin(); // Uses default VSPI pins

// Set up buffers
peripheral.set_buffers(spi_peripheral_tx_buf, spi_peripheral_rx_buf, BUF_SIZE);

Serial.println("Core X-Y: SPI Peripheral Initialized");

}

void loop() {

// While no message has been recieved from the controller
while (!peripheral.wait(portMAX_DELAY)) {
;
}

// Once a message has been received from the controller
// Get the message size
size_t msg_size = peripheral.get_received_trans_len();

// Print the number of bytes received
Serial.print("Core X-Y: Received ");
Serial.print(msg_size);
Serial.print(" bytes: ");

// Print the msg
for (uint16_t i = 0; i < msg_size; i++) {
Serial.print(spi_peripheral_rx_buf[i], HEX);
// Clear the buffer
spi_peripheral_rx_buf[i] = 0;
}
Serial.println();

// Interpret the message and perform appropriate action
handle_SPI_msg(spi_peripheral_rx_buf);

// Get updated sensor values and send to the bridge module
// The controller will only pick this message up on the next message that it delivers
send_data_update_SPI_msg(spi_peripheral_rx_buf, spi_peripheral_tx_buf);

// Clear message status
peripheral.pop();

}
Loading