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

Nose fix bugs #25

Merged
merged 6 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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 modified Nose/24thISE_nose.qproj
Binary file not shown.
1,296 changes: 1,296 additions & 0 deletions Nose/3Dmodels/ノーズ電装統合 v6.step

Large diffs are not rendered by default.

108 changes: 43 additions & 65 deletions Nose/Nose.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
#include <MCP342X.h>
#include <CCP_MCP2515.h>

bool can_avairable = true;

#define CAN0_CS 0
#define CAN0_INT 1
#define CAN0_CS D0
#define CAN0_INT D1
#define LED_YELLOW LED_BUILTIN
#define LED_BLUE PIN_LED_RXL

Expand All @@ -18,22 +16,19 @@ CCP_MCP2515 CCP(CAN0_CS, CAN0_INT); //CAN

const int clockFrequency = 400000; //I2C bus speed
bool timer100Hz = false;
bool sleep_sensors = false;
bool timer1Hz=false;
bool can_checkerflag = false;
struct repeating_timer st_timer;

void setup() {
Serial.begin(1843200);
Wire.setSDA(6);
Wire.setSCL(7);
Serial.begin(115200);
Wire.setSDA(6);//rp2040の場合は必要
Wire.setSCL(7);//rp2040の場合は必要
Wire.setClock(clockFrequency);
Wire.begin();
bme.begin(0x76);
myADC.configure(MCP342X_MODE_CONTINUOUS | MCP342X_CHANNEL_1 | MCP342X_SIZE_18BIT | MCP342X_GAIN_1X);
add_repeating_timer_us(10000, TimerIsr, NULL, &st_timer); //100Hz
if (can_avairable) {
CCP.begin();
}
CCP.begin();

}

void loop() {
Expand All @@ -42,54 +37,43 @@ void loop() {
static float barometic_pressure = 0.0;
static char adc_bytes[3] = { 0x00, 0x00, 0x00 };
static double voltage = 0.0;
static uint32_t pretime_100Hz=0;
static uint32_t pretime_1Hz=0;

//100Hz用
if(millis()-pretime_100Hz>10){
timer100Hz=true;
pretime_100Hz=millis();
}else{
timer100Hz=false;
}
//1Hz用
if(millis()-pretime_1Hz>1000){
timer1Hz=true;
pretime_1Hz=millis();
}else{
timer1Hz=false;
}

if (timer100Hz) {
timer100Hz = false;
if (!sleep_sensors) {
//差圧センサ関連
myADC.startConversion();
myADC.getResult(&result);
DevideBytes(&result, adc_bytes);
ConvertToVoltage(adc_bytes, &voltage); //3つのバイトを電圧に変換
//BME280関連
GetBME280Data(&temperature, &barometic_pressure);
//CAN送信
if (can_avairable) {
CCP.uint32_to_device(CCP_nose_adc, voltage);
CCP.float_to_device(CCP_nose_temperature, temperature);
CCP.float_to_device(CCP_nose_barometic_pressure, barometic_pressure);
if (can_checkerflag) {
CCP.string_to_device(CCP_nose_status, "OK");
can_checkerflag = false;
}
}
//シリアル出力
SerialPrintSensors(adc_bytes, temperature, barometic_pressure, voltage);
}
}
if (can_avairable) {
CCP.read_device();
switch (CCP.id) {
case CCP_EMST_mesure:
if (CCP.str_match("STOP", 4)) {
sleep_sensors = true;
} else if (CCP.str_match("CLEAR", 5)) {
sleep_sensors = false;
}
break;
case CCP_nose_adc:
if (CCP.str_match("CHECK", 5)) {
can_checkerflag = true;
}
if (CCP.str_match("KILL", 4)) {
sleep_sensors = true;
}
if (CCP.str_match("CLEAR", 5)) {
sleep_sensors = false;
}
break;
default:
break;
}
//差圧センサ関連
myADC.startConversion();
myADC.getResult(&result);
DevideBytes(&result, adc_bytes);
ConvertToVoltage(adc_bytes, &voltage); //3つのバイトを電圧に変換
//BME280関連
GetBME280Data(&temperature, &barometic_pressure);
//CAN送信
CCP.float_to_device(CCP_nose_temperature, temperature);
CCP.float_to_device(CCP_nose_barometic_pressure, barometic_pressure);
CCP.float_to_device(CCP_nose_voltage, static_cast<float>(voltage));
CCP.string_to_device(CCP_nose_adc, adc_bytes);
if(timer1Hz){
CCP.string_to_device(CCP_nose_status, "OK");
}
//シリアル出力
SerialPrintSensors(adc_bytes, temperature, barometic_pressure, voltage);
}
}

Expand Down Expand Up @@ -119,7 +103,6 @@ void ConvertToVoltage(char* bytes, double* voltage) {
}

void SerialPrintSensors(char* adc_bytes, float temperature, float barometic_pressure, double voltage) {
// if(timer100Hz) Serial.println("overrun");
Serial.print("time:");
Serial.print(micros());
Serial.print(",adc_bytes:");
Expand All @@ -134,8 +117,3 @@ void SerialPrintSensors(char* adc_bytes, float temperature, float barometic_pres
Serial.print(",voltage:");
Serial.println(voltage, 10);
}

bool TimerIsr(struct repeating_timer* t) {
timer100Hz = true;
return true;
}
14 changes: 12 additions & 2 deletions Nose/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# ノーズ電装
<img src="images/front.jpg" width="300"><img src="images/back.jpg" width="300">

<img src="images/in1.jpg" width="300"><img src="images/in2.jpg" width="300">

## 概要
- This component has role of sensoring airspeed,temperature and barometic pressure.
- This component communicates with the main electrical compnent via the CAN protocol.
- ピトー管で対気速度を測定する
- BMEで温度と気圧を測定する
- CANで他基板へデータを送信する
## ハードウェア
### BOM
#### MCU
Expand Down Expand Up @@ -30,12 +34,18 @@
### 回路
<img src="images/circuit.png" width="100%">

※CANの終端抵抗はTBD $\Omega$

### PCB
<img src="images/PCB1_ver2.png" width="300"><img src="images/PCB2.png" width="400">
## ソフトウェア
### 依存関係
- Wire.h
- CCP.h
- MCP342X.h[https://github.com/uChip/MCP342X]

## 寸法
<img src="images/1.png" width="300">

## 基礎知識

Expand Down
Binary file added Nose/images/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Nose/images/back.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Nose/images/circuit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Nose/images/front.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Nose/images/in1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Nose/images/in2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading