Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b1c5707
First version of tests.
pietrea2 Mar 21, 2021
41ba35f
Removed old folder
pietrea2 Mar 21, 2021
61ce8d6
restructured repo and added readme
urmilmodi Mar 28, 2021
303522d
corrected readme name
urmilmodi Mar 28, 2021
5af7d31
Added Gitignore
JLefebvre55 Apr 17, 2021
805b4f6
First version of tests.
pietrea2 Mar 21, 2021
5d7cd80
Removed old folder
pietrea2 Mar 21, 2021
ec763ca
restructured repo and added readme
urmilmodi Mar 28, 2021
63c7a08
corrected readme name
urmilmodi Mar 28, 2021
4774eec
Merge branch 'serial-can-bus-module' of https://github.com/UTHT/elect…
JLefebvre55 May 15, 2021
157a715
Sensor Implementation Template
JLefebvre55 May 21, 2021
05a75d9
Adafruit Compatibility Fix
JLefebvre55 May 27, 2021
c675e2d
Added Inverter Message Reference
JLefebvre55 Jul 15, 2021
e24bb9c
Add Page Numbers for Doc Reference
JLefebvre55 Jul 15, 2021
f6019b0
Add files via upload
pietrea2 Jul 31, 2021
d9f4150
Update and rename PM100_CAN_BUS.cpp.ino to PM100_CAN_BUS.cpp
pietrea2 Aug 9, 2021
371c29b
Fixed compilation errors
pietrea2 Aug 9, 2021
dadb85b
Added Speed Command. Cleaned up code, formatted main menu
pietrea2 Aug 9, 2021
91f0175
Broadcast Message Class
angusjhwu Aug 14, 2021
3c67435
Renamed function to create_command_message
pietrea2 Aug 14, 2021
c6793f4
Added negative torque option/calculation
pietrea2 Aug 14, 2021
7e8a913
Visual map of current state of code
pietrea2 Aug 14, 2021
1755d5d
Renamed file, to match naming convention ( /w broadcast)
pietrea2 Aug 14, 2021
7d2824f
Renamed file to match naming convention ( /w broadcast)
pietrea2 Aug 14, 2021
09abeda
Rename COMMAND_MESSAGE.cpp to Serial-CAN-Bus/COMMAND_MESSAGE.cpp
pietrea2 Aug 14, 2021
ed8c6ab
1st Ver of reading CAN Fault Code messages
pietrea2 Aug 16, 2021
77e9936
function analyzes EVERY BIT now, returns vector of faults
pietrea2 Aug 21, 2021
9b942ea
Added disable broadcast messages function
angusjhwu Aug 21, 2021
863b060
vms & inverter functions updated - return states now
pietrea2 Aug 24, 2021
831f144
VSM & Inverter functions update - return states now
pietrea2 Aug 24, 2021
79dace8
Updated Disable Broadcast Message Function
angusjhwu Aug 24, 2021
cf98fbe
Added read_fault_codes() function here
pietrea2 Sep 4, 2021
b808732
fixed weird white-space indexing
pietrea2 Sep 4, 2021
2c442b9
Added read_fault_codes() function code
pietrea2 Sep 4, 2021
ba30539
Merge branch 'staging' into serial-can-bus-module
JLefebvre55 Sep 4, 2021
4c4a449
Inverter Class
JLefebvre55 Sep 4, 2021
ac4a4f7
minor fix
JLefebvre55 Sep 4, 2021
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
Binary file added Inverter/Code Overview - Map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
129 changes: 129 additions & 0 deletions Inverter/Inverter.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// Headers for each sensor type
#include "src/InverterDebug.h"
//...
#include "src/Inverter.h"

#include "src/Serial_CAN_Module.h"

#include "Base.h"
#include "Sensor.h"
#include "Actuator.h"
#define NUMSENSORS 1 //Or however many
#define NUMACTUATORS 1 //Or however many
#define BAUDRATE 115200
#define THISARDUINO ARDUINO_ONE

#define CANBAUD 9600
#define CANTX 10
#define CANRX 11

Serial_CAN canbus();

// Objects for each sensor
InverterDebug inverterDebug(&canbus, THISARDUINO);
//...
Inverter inverter(&canbus, THISARDUINO);
//...

Sensor* sensors[NUMSENSORS] = {
&inverterDebug
};

Actuator* actuators[NUMACTUATORS] = {
&inverter
};

// !#!#!#!--- EVERYTHING AFTER HERE DOES NOT NEED TO BE CHANGED FOR SENSOR IMPLEMENTATION ---!#!#!#!

void setup(){
Serial.begin(BAUDRATE);
canbus.begin(CANTX, CANRX, CANBAUD);

bool success = true;
for(int i = 0; i < NUMSENSORS; i++){
SensorState* state = sensors[i]->begin();
// Print/send sensor post-setup state data here. For example:
bool _success = (state->error == ERR_NONE);
if(_success){
Serial.print("Sensor ");
Serial.print(sensors[i]->sensor);
Serial.println(" initialized.");
} else {
Serial.print("Sensor ");
Serial.print(sensors[i]->sensor);
Serial.println(" failed to initialize!");
}
success &= _success;
}
for(int i = 0; i < NUMACTUATORS; i++){
ActuatorState* state = actuators[i]->begin();
// Print/send sensor post-setup state data here. For example:
bool _success = (state->error == ERR_NONE);
if(_success){
Serial.print("Actuator ");
Serial.print(actuators[i]->actuator);
Serial.print(" initialized. ");

state = actuators[i]->update(); // Initial set to default target
_success = (state->error == ERR_NONE);
if(_success){
Serial.print("Set to ");
Serial.println(state->target);
} else {
Serial.print("\nActuator ");
Serial.print(sensors[i]->sensor);
Serial.println(" failed to set!");
}
} else {
Serial.print("Actuator ");
Serial.print(sensors[i]->sensor);
Serial.println(" failed to initialize!");
}
success &= _success;
}
if(!success){
Serial.println("POST failed on one or more devices, freezing...");
while(1){delay(1000);}
}
}

void loop(){
for(int i = 0; i < NUMSENSORS; i++){
SensorState* state = sensors[i]->update();
// Print/send sensor post-setup state data here. For example:
bool _success = (state->error == ERR_NONE);
bool _new = (state->debug == DS_SUCCESS);
if(_success && _new) {
Serial.print("Sensor ");
Serial.print(sensors[i]->sensor);
Serial.print(" read success: ");
for(int x = 0; x < state->numdata; x++) {
Serial.print(state->data[x].data);
Serial.print(' ');
Serial.print(state->data[x].units);
if(x < state->numdata-1){Serial.print(", ");}
}
} else if (!_success) {
Serial.print("Sensor ");
Serial.print(sensors[i]->sensor);
Serial.println(" failed to update!");
// TODO: Recover failed sensor?
}
}
for(int i = 0; i < NUMACTUATORS; i++){
ActuatorState* state = actuators[i]->update();

bool _success = (state->error == ERR_NONE) && (state->debug == DS_SUCCESS);
if(_success){
Serial.print("Actuator ");
Serial.print(actuators[i]->actuator);
Serial.print(" set success: ");
Serial.println(state->target);
} else {
Serial.print("Actuator ");
Serial.print(actuators[i]->actuator);
Serial.println(" failed to set!");
// TODO: Recover failed sensor?
}
}
}
68 changes: 68 additions & 0 deletions Inverter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Serial CAN Bus

> Documentation for the **Serial CAN Bus** can be found [here](https://drive.google.com/drive/folders/1rzmLET68QOWb4At4mAyN4rDsj-VGBLyh?usp=sharing).


## Todo

- [ ] Setup, testing, and expected output documentation (screenshot, pictures, logs/stack traces, etc.);
- [ ] A list of dependencies (and links to those);
- [ ] Everything else that is listed under [the master `README`](../README.md).
<br>
<br>

# PM100 Inverter/Controller CAN Bus Message Reference

> Prepared by Adam Pietrewicz, adapted to Markdown by Jayden Lefebvre (@JLefebvre55)
>
> Last Updated - July 14th 2021

***

## Broadcast Messages

> CAN ID: `0x0A0-0x0AF`. See doc for example implementation (pgs. 4-5) and per-byte breakdown (pgs. 5-11).

| Address | Frequency | Content | CAN Active Messages (Low Word) |
|-----------|---------------|---------------------------------------------------------|----------------------------------|
| `0x0A0` | Slow/10Hz | Temperatures #1 | `0x0001` |
| `0x0A1` | Slow/10Hz | Temperatures #2 | `0x0002` |
| `0x0A2` | Slow/10Hz | Temperatures #3 | `0x0004` |
| `0x0A3` | Fast/100Hz | Analog Inputs Voltages | `0x0008` |
| `0x0A4` | Fast/100Hz | Digital Input Status | `0x0010` |
| `0x0A5` | Fast/100Hz | Motor Position Information | `0x0020` |
| `0x0A6` | Fast/100Hz | Current Information | `0x0040` |
| `0x0A7` | Fast/100Hz | Voltage Information | `0x0080` |
| `0x0A8` | Fast/100Hz | Flux Information | `0x0100` |
| `0x0A9` | Slow/10Hz | Internal Voltages | `0x0200` |
| `0x0AA` | Fast/100Hz | Internal States | `0x0400` |
| `0x0AB` | Fast/100Hz | Fault Codes | `0x0800` |
| `0x0AC` | Fast/100Hz | Torque & Timer Information | `0x1000` |
| `0x0AD` | Fast/100Hz | Modulation Index & Flux Weakening<br>Output Information | `0x2000` |
| `0x0AE` | Slow/10Hz | Firmware Information | `0x4000` |
| `0x0AF` | 100Hz (fixed) | Diagnostic Data | `0x8000` |

***
## Command Messages

> CAN ID: `0x0C0`. See doc for example implementation (pgs. 2-3).

| Byte(s) | Name | Format | Description |
|----------|------------------------|------------------|------------------------------------------------------------------------------------------------------------------------|
| 0, 1 | Torque Command | Torque | Torque command used when in torque mode. |
| 2, 3 | Speed Command | Angular Velocity | Speed command used when in speed mode. |
| 4 | Direction Command | Boolean | `0` - "Reverse", `1` - "Forward" (See Section 2.3.2.2) |
| 5: Bit 0 | Inverter Enable | Boolean | `0` - Inverter Off, `1` - Inverter On |
| 5: Bit 1 | Inverter Discharge | Boolean | `0` - Disable Discharge, `1` - Enable Discharge |
| 5, 2 | Speed Mode Enable | Boolean | `0` - Do not override mode, `1` - Overrides from torque <br>mode to speed mode ONLY (See "Using Speed Mode" in manual) |
| 6, 7 | Commanded Torque Limit | Torque | Motor and Regen Torque limits. If set to `0`, default <br>torque limit from EEPROM is used. |

***
## Parameter Messages

> Sets EEPROM parameters.

**CAN ID `0x0C1`** - Used to send message *to* controller.

**CAN ID `0x0C2`** - Response *from* controller.
***
Loading