- LEGACY/Hexapod_Teensy/: old robot sketch (reference only). - platformio.ini: robot env targets teensy36 (owner-confirmed board). - Config.h: per-servo SERVOS table (pin, pulse at 0 deg, signed us/deg, pulse limits) built from the old sketch's pins, ranges, trims and the old Unity servo directions. Rear-left/front-left coxa offsets set to 0: the owner re-horns those two servos (the old +-90 left them at the end of travel; the sim showed them clamping). - ServoDriver: 18 servos on hardware PWM (50 Hz, 16-bit); the Teensy 3.6 Servo library stops at 12. - Radio on CE 39 / CSN 15 with SPI SCK on pin 14. - sim: analogWrite/PWM shims, pulses decoded through SERVOS (API v6). - Docs: CLAUDE.md, READMEs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
67 lines
1.4 KiB
C
67 lines
1.4 KiB
C
#include <SPI.h>
|
|
#include "RF24.h"
|
|
#include <RF24Network.h>
|
|
#include "TransferDataStructure.h"
|
|
|
|
// Nrf24 settings
|
|
RF24 radio(39, 15); // CE, CSN
|
|
RF24Network network(radio);
|
|
|
|
const uint16_t this_node = 01; // Address of our node in Octal format
|
|
const uint16_t other_node = 00; // Address of the other node in Octal format
|
|
|
|
void NrfInit()
|
|
{
|
|
SPI.setSCK(14);
|
|
SPI.setMOSI(11);
|
|
SPI.setMISO(12);
|
|
|
|
SPI.begin();
|
|
radio.begin();
|
|
network.begin(/*channel*/ 90, /*node address*/ this_node);
|
|
|
|
// Set the PA Level low to prevent power supply related issues since this is a
|
|
// getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
|
|
radio.setPALevel(RF24_PA_LOW);
|
|
}
|
|
|
|
dataStruct2 NrfGetData(dataStruct2 data, bool debug = false)
|
|
{
|
|
// network.update();
|
|
int timeout = millis() + 100;
|
|
while ( network.available() && timeout > millis() )
|
|
{
|
|
RF24NetworkHeader header;
|
|
network.read(header, &data, sizeof(data));
|
|
|
|
if (debug)
|
|
{
|
|
Serial.print("Received packet ");
|
|
Serial.println(data.servoPositions[0]);
|
|
}
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
dataStruct2 NrfSendData(dataStruct2 data, bool debug = false)
|
|
{
|
|
// network.update();
|
|
|
|
if (debug)
|
|
Serial.print("Sending...");
|
|
|
|
RF24NetworkHeader header(/*to node*/ other_node);
|
|
bool ok = network.write(header, &data, sizeof(data));
|
|
|
|
if (debug)
|
|
{
|
|
if (ok)
|
|
Serial.println("ok.");
|
|
else
|
|
Serial.println("failed.");
|
|
}
|
|
|
|
return data;
|
|
}
|