Skip to content

Commit

Permalink
Merge in only the valuable changes from the Pressurizer branch
Browse files Browse the repository at this point in the history
  • Loading branch information
giseburt committed Jul 27, 2020
1 parent cfd1f67 commit 423c83f
Show file tree
Hide file tree
Showing 22 changed files with 2,259 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Expand Up @@ -49,7 +49,7 @@
"servertype": "jlink",
"cwd": "${workspaceRoot}/g2core/",
"executable": "./bin/MiniMillgShield-gShield/g2core.elf",
"device": "ATSAMS3X8E",
"device": "ATSAM3X8E",
"svdFile": "${workspaceRoot}/Motate/MotateProject/motate/cmsis/TARGET_Atmel/sam3x/ATSAM3X8E.svd",
"interface": "swd",
"showDevDebugOutput": false,
Expand Down
2 changes: 1 addition & 1 deletion g2core/board/ArduinoDue.mk
Expand Up @@ -62,7 +62,7 @@ ifeq ("$(BASE_BOARD)","g2core-due")
# Note: we call it "g2core-due" instead of "due" since the Motate built-in provides
# a "due" BASE_BOARD.
BOARD_PATH = ./board/ArduinoDue
SOURCE_DIRS += ${BOARD_PATH} device/step_dir_driver device/esc_spindle device/laser_toolhead
SOURCE_DIRS += ${BOARD_PATH} device/step_dir_driver device/esc_spindle device/laser_toolhead device/bme280 device/honeywell-trustability-ssc

PLATFORM_BASE = ${MOTATE_PATH}/platform/atmel_sam

Expand Down
18 changes: 17 additions & 1 deletion g2core/board/ArduinoDue/0_hardware.cpp
Expand Up @@ -58,6 +58,8 @@
#define SPINDLE_PWM_NUMBER 6
#endif

SPIBus_used_t spiBus;

#include "safety_manager.h"

SafetyManager sm{};
Expand Down Expand Up @@ -115,8 +117,22 @@ void hardware_init()
* hardware_periodic() - callback from the controller loop - TIME CRITICAL.
*/

#if HAS_PRESSURE
float pressure = 0;
float pressure_threshold = 0.01;
#endif

stat_t hardware_periodic()
{

#if HAS_PRESSURE
float new_pressure = pressure_sensor.getPressure(PressureUnits::cmH2O);
if (std::abs(pressure - new_pressure) >= pressure_threshold) {
pressure = new_pressure; // only record if goes past threshold!
sr_request_status_report(SR_REQUEST_TIMED);
}
#endif

return STAT_OK;
}

Expand Down Expand Up @@ -214,7 +230,7 @@ stat_t hw_flash(nvObj_t *nv)
return(STAT_OK);
}

#if !HAS_LASER
#if HAS_PRESSURE
// Stub in getSysConfig_3
// constexpr cfgItem_t sys_config_items_3[] = {};
constexpr cfgSubtableFromStaticArray sys_config_3{};
Expand Down
36 changes: 35 additions & 1 deletion g2core/board/ArduinoDue/board_gpio.cpp
Expand Up @@ -88,12 +88,46 @@ gpioDigitalOutputPin<OutputType<OUTPUT13_PWM, Motate::kOutput13_PinNumber>> dout
gpioDigitalInput* const d_in[] = {&din1, &din2, &din3, &din4, &din5, &din6, &din7, &din8, &din9};
gpioDigitalOutput* const d_out[] = {&dout1, &dout2, &dout3, &dout4, &dout5, &dout6, &dout7, &dout8, &dout9, &dout10, &dout11, &dout12, &dout13};
// not yet used
gpioAnalogInput* a_in[] = {};
gpioAnalogInput* a_in[] = {};
// gpioAnalogOutput* a_out[A_OUT_CHANNELS];

#if HAS_PRESSURE
Motate::SPIChipSelectPin<Motate::kPressure_ChipSelectPinNumber> pressure_cs{};
// BME280<SPIBus_used_t::SPIBusDevice> pressure_sensor{spiBus, pressure_cs};
TruStabilitySSC<SPIBus_used_t::SPIBusDevice> pressure_sensor{spiBus,
pressure_cs,
/*min_output:*/ 1638, // 10% of 2^12
/*max_output:*/ 14745, // 90% of 2^12
/*min_value:*/ 0.0, // 0psi
/*max_value:*/ 15.0, // 15psi
PressureUnits::PSI};
#endif

/************************************************************************************
**** CODE **************************************************************************
************************************************************************************/

// Register a SysTick event to call start_sampling every temperature_sample_freq ms
const int16_t ain_sample_freq = 2;
int16_t ain_sample_counter = ain_sample_freq;
Motate::SysTickEvent ain_tick_event{
[] {
if (!--ain_sample_counter) {
ai1.startSampling();
ai2.startSampling();
ai3.startSampling();
ai4.startSampling();

#if HAS_PRESSURE
pressure_sensor.startSampling(); // has a timeout built in to prevent over-calling
#endif

ain_sample_counter = ain_sample_freq;
}
},
nullptr
};

/*
* gpio_reset() - reset inputs and outputs (no initialization)
*/
Expand Down
7 changes: 7 additions & 0 deletions g2core/board/ArduinoDue/board_gpio.h
Expand Up @@ -96,5 +96,12 @@ extern gpioDigitalOutputPin<OutputType<OUTPUT11_PWM, Motate::kOutput11_PinNumber
extern gpioDigitalOutputPin<OutputType<OUTPUT12_PWM, Motate::kOutput12_PinNumber>> dout12;
extern gpioDigitalOutputPin<OutputType<OUTPUT13_PWM, Motate::kOutput13_PinNumber>> dout13;

#if HAS_PRESSURE
// #include "bme280.h"
// extern BME280<SPIBus_used_t::SPIBusDevice> pressure_sensor;

#include "honeywell-trustability-ssc.h"
extern HoneywellTruStability<SPIBus_used_t::SPIBusDevice> pressure_sensor;
#endif // HAS_PRESSURE

#endif // End of include guard: BOARD_GPIO_H_ONCE
2 changes: 2 additions & 0 deletions g2core/board/ArduinoDue/gShield-pinout.h
Expand Up @@ -213,6 +213,8 @@ pin_number kSD_CardDetectPinNumber = -1;
pin_number kInterlock_InPinNumber = -1;
pin_number kOutputSAFE_PinNumber = -1; // SAFE signal

pin_number kPressure_ChipSelectPinNumber = kSocket2_SPISlaveSelectPinNumber;

pin_number kLED_USBRXPinNumber = 72;
pin_number kLED_USBTXPinNumber = 73;

Expand Down
9 changes: 9 additions & 0 deletions g2core/board/ArduinoDue/hardware.h
Expand Up @@ -51,6 +51,10 @@
#define HAS_LASER 0
#endif

#ifndef HAS_PRESSURE
#define HAS_PRESSURE 0
#endif

#if HAS_LASER
#define MOTORS 5 // number of motors + one "laser" motor (used for pulsing the laser in sync)
#else
Expand Down Expand Up @@ -126,6 +130,11 @@ typedef TimerChannel<3,0> dda_timer_type; // stepper pulse generation in s
typedef TimerChannel<4,0> exec_timer_type; // request exec timer in stepper.cpp
typedef TimerChannel<5,0> fwd_plan_timer_type; // request exec timer in stepper.cpp

/**** SPI Setup ****/
#include "MotateSPI.h"
typedef Motate::SPIBus<Motate::kSPI_MISOPinNumber, Motate::kSPI_MOSIPinNumber, Motate::kSPI_SCKPinNumber> SPIBus_used_t;
extern SPIBus_used_t spiBus;

// Pin assignments

pin_number indicator_led_pin_num = Motate::kLED_USBRXPinNumber;
Expand Down
2 changes: 1 addition & 1 deletion g2core/board/gquintic.mk
Expand Up @@ -60,7 +60,7 @@ ifeq ("$(BASE_BOARD)","gquintic")
endif

BOARD_PATH = ./board/gquintic
SOURCE_DIRS += ${BOARD_PATH} device/trinamic device/step_dir_hobbyservo device/max31865 device/i2c_eeprom device/i2c_multiplexer device/i2c_as5601 device/esc_spindle device/laser_toolhead
SOURCE_DIRS += ${BOARD_PATH} device/trinamic device/step_dir_hobbyservo device/max31865 device/i2c_eeprom device/i2c_multiplexer device/i2c_as5601 device/esc_spindle device/laser_toolhead device/bme280 device/honeywell-trustability-ssc

PLATFORM_BASE = ${MOTATE_PATH}/platform/atmel_sam
include $(PLATFORM_BASE).mk
Expand Down
91 changes: 72 additions & 19 deletions g2core/board/gquintic/0_hardware.cpp
Expand Up @@ -35,23 +35,27 @@
#include "board_gpio.h"
#include "safety_manager.h"

#include "kinematics.h" // for get_flow_volume

#include "MotateUtilities.h"
#include "MotateUniqueID.h"
#include "MotatePower.h"

#include "settings.h"

//Motate::ClockOutputPin<Motate::kExternalClock1_PinNumber> external_clk_pin {16000000}; // 16MHz optimally
Motate::OutputPin<Motate::kExternalClock1_PinNumber> external_clk_pin {Motate::kStartLow};

HOT_DATA SPI_CS_PinMux_used_t spiCSPinMux;
HOT_DATA SPIBus_used_t spiBus;

// HOT_DATA TWIBus_used_t twiBus;
HOT_DATA TWIBus_used_t twiBus;

// // Define Multiplexers
// HOT_DATA plex0_t plex0{twiBus, 0x0070L};
// HOT_DATA plex1_t plex1{twiBus, 0x0071L};


// #include "i2c_eeprom.h"
// HOT_DATA I2C_EEPROM eeprom{twiBus, 0b01010000};
// alignas(4) uint8_t eeprom_buffer[128] HOT_DATA = "TestinglyABCDEFGHIJKLmnop";
// alignas(4) uint8_t eeprom_in_buffer[128] HOT_DATA = "";
Expand Down Expand Up @@ -123,7 +127,7 @@ ToolHead *toolhead_for_tool(uint8_t tool) {
void hardware_init()
{
spiBus.init();
// twiBus.init();
twiBus.init();
board_hardware_init();
external_clk_pin = 0; // Force external clock to 0 for now.

Expand All @@ -139,12 +143,22 @@ void hardware_init()
*/

// previous values of analog voltages
#if TEMPERATURE_OUTPUT_ON
float ai_vv[A_IN_CHANNELS];
const float analog_change_threshold = 0.01;
#endif

float angle_0 = 0.0;
float angle_1 = 0.0;

#if HAS_PRESSURE
float pressure = 0;
float pressure_threshold = 0.01;

float flow = 0;
float flow_threshold = 0.01;
#endif

// void read_encoder_0(bool worked /* = false*/, float angle /* = 0.0*/) {
// if (worked) {
// angle_0 = angle;
Expand All @@ -159,6 +173,7 @@ float angle_1 = 0.0;
// encoder_1.getAngleFraction();
// }

// Following is for testing internally
// void first_part(bool worked = false);
// void second_part(bool worked = false);
// void third_part(bool worked = false);
Expand Down Expand Up @@ -204,17 +219,25 @@ stat_t hardware_periodic()
}
#endif

// static uint8_t sent = false;
// if (!sent) {
// sent = 2;
// encoder_0.getAngleFraction(read_encoder_0);
// encoder_1.getAngleFraction(read_encoder_1);
// } else if (sent > 1 && sent < 80) {
// sent++;
// }
#if HAS_PRESSURE
float new_pressure = pressure_sensor1.getPressure(PressureUnits::cmH2O);
if (std::abs(pressure - new_pressure) >= pressure_threshold) {
pressure = new_pressure; // only record if goes past threshold!
sr_request_status_report(SR_REQUEST_TIMED);
}

float new_flow = flow_sensor1.getFlow(FlowUnits::SLM);
if (std::abs(flow - new_flow) >= flow_threshold) {
flow = new_flow; // only record if goes past threshold!
sr_request_status_report(SR_REQUEST_TIMED);
}
#endif


// if (sent == 3) {
// static uint8_t sent = 0;
// if (!sent) {
// first_part(false);
// sent = 2;
// }

return STAT_OK;
Expand Down Expand Up @@ -315,14 +338,39 @@ stat_t hw_flash(nvObj_t *nv)
return(STAT_OK);
}

#if !HAS_LASER
#if HAS_PRESSURE

// Stub in getSysConfig_3
// constexpr cfgItem_t sys_config_items_3[] = {};
constexpr cfgSubtableFromStaticArray sys_config_3{};
const configSubtable * const getSysConfig_3() { return &sys_config_3; }
stat_t get_pressure(nvObj_t *nv)
{
nv->value_flt = pressure_sensor1.getPressure(PressureUnits::cmH2O);
nv->valuetype = TYPE_FLOAT;
return (STAT_OK);
}

stat_t get_flow(nvObj_t *nv)
{
nv->value_flt = flow_sensor1.getFlow(FlowUnits::SLM);
nv->valuetype = TYPE_FLOAT;
return (STAT_OK);
}

stat_t get_flow_pressure(nvObj_t *nv)
{
nv->value_flt = flow_sensor1.getPressure(PressureUnits::cmH2O);
nv->valuetype = TYPE_FLOAT;
return (STAT_OK);
}

#else

constexpr cfgItem_t sys_config_items_3[] = {
{ "prs","prs1", _f0, 5, tx_print_nul, get_pressure, set_nul, nullptr, 0 },
{ "flow1","flow1prs", _f0, 5, tx_print_nul, get_flow_pressure, set_nul, nullptr, 0 },
{ "flow1","flow1slm", _f0, 5, tx_print_nul, get_flow, set_nul, nullptr, 0 },
{ "flow1","flow1vol", _f0, 5, tx_print_nul, get_flow_volume, set_nul, nullptr, 0 },
};
constexpr cfgSubtableFromStaticArray sys_config_3{sys_config_items_3};

#elif HAS_LASER

stat_t set_pulse_duration(nvObj_t *nv)
{
Expand Down Expand Up @@ -385,10 +433,15 @@ constexpr cfgItem_t sys_config_items_3[] = {
};

constexpr cfgSubtableFromStaticArray sys_config_3{sys_config_items_3};
const configSubtable * const getSysConfig_3() { return &sys_config_3; }

#else // !HAS_LASER && !HAS_PRESSURE

// Stub in getSysConfig_3
constexpr cfgSubtableFromStaticArray sys_config_3{};
#endif

const configSubtable * const getSysConfig_3() { return &sys_config_3; }

/***********************************************************************************
* TEXT MODE SUPPORT
* Functions to print variables from the cfgArray table
Expand Down

0 comments on commit 423c83f

Please sign in to comment.