Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gustavodev #15

Merged
merged 43 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
06fbe85
ZXY6005s powersupply library prototype
May 15, 2023
0420c96
Correct folder reupload
May 15, 2023
ae17136
Reviving old code
May 27, 2023
9b10458
Arduino driver WIP
Jun 21, 2023
81ac2a3
Arduino Driver WIP v2
Jun 23, 2023
f6ee8bb
Arduino Driver WIP v2.3
Jun 23, 2023
2c78dba
Arduino driver v2.4
Jun 26, 2023
fc142f1
Updated Arduino Nano code.
Jun 29, 2023
d3fe2c3
ZXY6005s library (finished
Jul 27, 2023
f37e3c9
Reorganized Helmholtz source code files
Aug 4, 2023
0726171
Adding more functions to the HC shell
Aug 6, 2023
763b1c2
Adding more functions to the HC shell
Aug 11, 2023
c7be74f
Corrections made to Arduino functions.
Aug 11, 2023
1836745
Updated Arduino driver v2.5
Aug 11, 2023
6131d35
PSU driver duplicate
Aug 11, 2023
56f9ccc
Updated Arduino object constructor and main constructor.
Aug 14, 2023
ba2190b
Updated ZXY6005s constructor.
Aug 14, 2023
3052a5e
Updated ZXY6005s constructor.
Aug 14, 2023
608a90e
Updated main to work with updated Arduino driver. Removed properties …
Aug 14, 2023
3274b2f
Updated ZXY6005s functions that return int values.
Aug 14, 2023
536b950
Updated ZXY6005s functions that return int values.
Aug 14, 2023
0dc14f6
Updated psu power function in main.
Aug 14, 2023
b8c01d9
Updated exit function.
Aug 14, 2023
b219ee1
Fixed an issue with ZXY6005s return voltage function.
Aug 16, 2023
0d109d1
Fixed an issue with setting Z H-bridge to positive polarity.
Aug 16, 2023
09ea87c
Fixed an issue with setting Y H-Bridge to negative polarity.
Aug 16, 2023
744c18d
Rewrote commands for ZXY and changed a mode function.
Aug 21, 2023
f0c2f3d
Attempt to fix setting the current function in the HC shell.
Aug 21, 2023
264bf6a
Fully functional HC shell. Fixed all bugs
Aug 21, 2023
f2562b2
Added Calibration Function. Can write to a .CSV and sweep test all axis.
Sep 4, 2023
2a16acf
Added Calibration Function. Can write to a .CSV and sweep test all axis.
Sep 14, 2023
e3a30e6
Added Calibration function help message. WIP
Sep 14, 2023
e8f750f
Fixed calibration parameters
Sep 14, 2023
1190d6c
Fixed calibration parameters
Sep 14, 2023
d06f215
Fixed calibration parameters
Sep 14, 2023
f6959f4
Fixed calibration parameters
Sep 14, 2023
c6d07b0
Fixed calibration parameters
Sep 14, 2023
1cea8a8
Fixed typo
Sep 14, 2023
8216b6c
Added missing variable in for loop
Sep 14, 2023
7b6aeca
Fixed typo
Sep 14, 2023
9bacb0c
Fixed for loop issues
Sep 14, 2023
f999ccc
Fixed for loop issues
Sep 14, 2023
dd331b8
Fixed an issue where currents were not recorded
Sep 14, 2023
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
159 changes: 159 additions & 0 deletions Arduino_Comms/PSAS_HHCage/PSAS_HHCage.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#include <Adafruit_MMC56x3.h>
/* Assign a unique ID to this sensor at the same time */
Adafruit_MMC5603 mmc = Adafruit_MMC5603(12345);

//Assigning pins to variables
int xina = 6;
int xinb = 7;
int yina = 4;
int yinb = 5;
int zina = 2;
int zinb = 3;
int xstat = 0;
int ystat = 0;
int zstat = 0;
int magstat = 0;


int incomingByte = 0; // for incoming serial data

void setup() {
// Setting pins as output.
pinMode(xina, OUTPUT);
pinMode(xinb, OUTPUT);
pinMode(yina, OUTPUT);
pinMode(yinb, OUTPUT);
pinMode(zina, OUTPUT);
pinMode(zinb, OUTPUT);

//Setting all pins off
digitalWrite(xina,LOW);
digitalWrite(xinb,LOW);
digitalWrite(yina,LOW);
digitalWrite(yinb,LOW);
digitalWrite(zina,LOW);
digitalWrite(zinb,LOW);

//Baudrate/bytes per second set.
Serial.begin(115200);


// Initialise the mag sensor */
if (mmc.begin(MMC56X3_DEFAULT_ADDRESS, &Wire)) { // I2C mode
magstat = 1;
//mmc.printSensorDetails();
}

}

void loop() {
// put your main code here, to run repeatedly:

// reply only when you receive data:
if (Serial.available() > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While single-char commands are technically fine, it might be helpful to future you, ( as well as any future developers), to actually expand these to human-readable command strings.

This would lend itself to opening up a telnet client to the arduino for manual testing which allows you to develop this apart from the python client.

// read the incoming byte:
incomingByte = Serial.read();

// say what you got:
// Serial.print("I received: ");
// Serial.println(incomingByte, DEC);
}
if (incomingByte != 0){
//Shutdown
if (incomingByte == 97){
digitalWrite(xina,LOW);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this and similar situations. I would recommend abstracting this to either a static function or some kind of variable-fed function such as:

static void write(const byte[] write_bytestring, byte*& result) {
   // Conditionally set bits based on the bytestring here
   
   // load result so we can verify the bits were set
}

This can help separate code so it improves readability and leave a hook for unit-testing.

digitalWrite(xinb,LOW);
digitalWrite(yina,LOW);
digitalWrite(yinb,LOW);
digitalWrite(zina,LOW);
digitalWrite(zinb,LOW);
xstat = 0;
ystat = 0;
zstat = 0;
}
//X Bridge Off character: 'b' Not working
if (incomingByte == 'b'){
digitalWrite(xina,LOW);
digitalWrite(xinb,LOW);
xstat = 0;
}
//Y Bridge Off character: 'c' Not working
if (incomingByte == 'c'){
digitalWrite(yina,LOW);
digitalWrite(yinb,LOW);
ystat = 0;
}
//Z Bridge Off character: 'd' Not working
if (incomingByte == 'd'){
digitalWrite(zina,LOW);
digitalWrite(zinb,LOW);
zstat = 0;
}
//H-Bridge Status message
if (incomingByte == 's'){
Serial.print(xstat);
Serial.print(ystat);
Serial.println(zstat);
}
//mag Status message
if (incomingByte == 'q'){
Serial.println(magstat);
}
//positive "x"
if (incomingByte == 'x'){
digitalWrite(xinb,LOW);
digitalWrite(xina,HIGH);
xstat = 1;
}
//negative "X" Not working
if (incomingByte == 'X'){
digitalWrite(xina,LOW);
digitalWrite(xinb,HIGH);
xstat = 2;
}
//positive "y"
if (incomingByte == 'y'){
digitalWrite(yinb,LOW);
digitalWrite(yina,HIGH);
ystat = 1;
}
//negative "Y" Not working
if (incomingByte == 'Y'){
digitalWrite(yina,LOW);
digitalWrite(yinb,HIGH);
ystat = 2;
}
//positive "z"
if (incomingByte == 'z'){
digitalWrite(zinb,LOW);
digitalWrite(zina,HIGH);
zstat = 1;
}
//negative "Z" Not working
if (incomingByte == 'Z'){
digitalWrite(zina,LOW);
digitalWrite(zinb,HIGH);
zstat = 2;
}
//mag reading
if (incomingByte == 'm'){
sensors_event_t event;
mmc.getEvent(&event);
Serial.print(event.magnetic.x);
Serial.print(",");
Serial.print(event.magnetic.y);
Serial.print(",");
Serial.println(event.magnetic.z);
}
//temp reading
if (incomingByte == 't'){
sensors_event_t event;
mmc.getEvent(&event);
float temp_c = mmc.readTemperature();
Serial.println(temp_c);
}
//end of loop
incomingByte = 0;
Serial.flush();
}
}
2 changes: 1 addition & 1 deletion cage_controller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import serial # Stuff for controlling the power supplies
import time # Stuff for regulated sensor delays
import smbus # Stuff for controlling temperature and magnetic sensors
import smbus2 # Stuff for controlling temperature and magnetic sensors
import utilities as utils # Stuff for debugging and/or general info
from gpiozero import LED

Expand Down
7 changes: 6 additions & 1 deletion command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,9 @@ def poll_data(duration = 10.0, dt = 1.0):
time_step.append(time_step[-1] + dt)
# temp_array.append(temperature())
mag_array.append(cage_controller.magnetometer())
return time_step, mag_array #temp_array, mag_array
return time_step, mag_array #temp_array, mag_array

if __name__ == "__main__":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file intended to be the entry point? If so, why here and not __main__ ?

interface()


Loading