Some initial progress

This commit is contained in:
Jared Dunbar 2023-02-19 00:00:25 -05:00
parent 0d4be65217
commit 383581f454
5 changed files with 112 additions and 0 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.pio .pio
src/wifi.h

View File

@ -0,0 +1,39 @@
#include "Arduino.h"
#include <stdint.h>
#include "Syren50.h"
void Syren50::init() {
Serial1.begin(9600);
delay(1000); // Give about 1 second to boot up, per datasheet
Serial.write(0b10101010);
}
void Syren50::command(uint8_t command, uint8_t data) {
Serial1.write(0x80); // Address
Serial1.write(command); // Command
Serial1.write(data);
Serial1.write((0x80 + command + data) & 0b01111111); // Checksum
Serial1.flush();
}
void Syren50::forwards(uint8_t speed) {
command(0x00, speed);
}
void Syren50::reverse(uint8_t speed) {
command(0x01, speed);
}
void Syren50::move(int8_t direction, uint8_t speed) {
if (direction == 1) {
forwards(speed);
} else if (direction == -1) {
reverse(speed);
} else {
forwards(0);
}
}
void Syren50::minInputVoltage(float voltage) {
command(0x03, (uint8_t)((voltage - 6.0) * 5.0));
}

18
lib/SyRen50/src/Syren50.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef SYREN50_H
#define SYREN50_H
#include <stdint.h>
class Syren50 {
public:
void init();
void forwards(uint8_t speed);
void reverse(uint8_t speed);
void move(int8_t direction, uint8_t speed);
void minInputVoltage(float voltage);
private:
void command(uint8_t command, uint8_t data);
};
#endif

View File

@ -7,3 +7,18 @@
; ;
; Please visit documentation for the other options and examples ; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html ; https://docs.platformio.org/page/projectconf.html
[platformio]
default_envs = esp12e
name = WiFiTrainReceiver
[env:esp12e]
platform = espressif8266
framework = arduino
board = esp12e
[env:nodemcuv2]
platform = espressif8266
framework = arduino
board = nodemcuv2

39
src/main.cpp Normal file
View File

@ -0,0 +1,39 @@
#include "Arduino.h"
#include "wifi.h"
#include <ESP8266WiFi.h>
#include <string>
#include "SyRen50.h"
using namespace std;
Syren50 motor;
void setup() {
Serial.begin(9600);
// delay required for motor controller boot-up
delay(1000);
motor.init();
}
float throttle = 0.0f;
uint8_t direction = 0;
bool horn = false;
bool bell = false;
bool lights = false;
uint8_t last_direction = 0;
float last_throttle = 0.0f;
void inertia(float throttle, uint8_t direction, float &inertial_throttle, uint8_t &inertial_direction) {
inertial_throttle = throttle;
inertial_direction = direction;
}
float motor_throttle;
uint8_t motor_direction;
void loop() {
//get_control_inputs(throttle, direction, horn, bell, lights);
inertia(throttle, direction, motor_throttle, motor_direction);
motor.move(motor_direction, motor_throttle);
delay(1);
}