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

battery monitor tx message #209

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from
Draft

Conversation

siannnhannn
Copy link

No description provided.

#include <opencan_rx.h>
#include <opencan_tx.h>

#include <math.h>
Copy link
Member

Choose a reason for hiding this comment

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

Include only the headers you need.

#include <string.h>

// hypothetical battery percent data
typedef struct {
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to make a CAN data struct, this is already generated by OpenCAN, we just have to implement a populate function.


static void batt_1Hz();

// task scheduling
Copy link
Member

Choose a reason for hiding this comment

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

Don't add redundant comments.


static void batt_1Hz()
{
/*
Copy link
Member

Choose a reason for hiding this comment

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

Not in this scope, the battery monitor will just report the battery percentage.

batteryPercent = 0;
}

void CANTX_populate_BATT_BatteryPercentData(
Copy link
Member

Choose a reason for hiding this comment

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

Where's the associated entry in can/network.yml?



firmware, flash = env.SConscript(
'src/SConscript.py',
Copy link
Member

Choose a reason for hiding this comment

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

Where is the SConscript.py under src/?

#ifndef BATT_H
#define BATT_H

#endif // BATT.H
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#endif // BATT.H
#endif /* BATT_H */

@@ -13,6 +13,7 @@
'steer',
'sup',
'throttle',
'batt',
Copy link
Member

Choose a reason for hiding this comment

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

Let's try to keep this list in alphabetical order.

],
)
for src in [
'batt.c', # Ensure this file exists in your source directory
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'batt.c', # Ensure this file exists in your source directory
'batt.c',

]
]

# Correct the typo in the variable name
Copy link
Member

Choose a reason for hiding this comment

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

Why didn't you just fix it?

Copy link
Member

Choose a reason for hiding this comment

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

This should have stayed a symlink!

(sizeof(adc_digi_output_data_t) * FRAME_SAMPLES * ADC_CHANNELS)

#define SAMPLES_OUT_SIZE 1024 // how to decide the size of the output
#define PREV_SAMPLES_DELAY 0.010 // why is this the delay time
Copy link
Member

Choose a reason for hiding this comment

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

To answer the comment, this was arbitrarily chosen :)

Comment on lines +29 to +35
#define ADC_CONV ADC_CONV_SINGLE_UNIT_1
#define ADC_DIGI_OUTPUT_FORMAT ADC_DIGI_OUTPUT_FORMAT_TYPE2

#define BV_ADC_ATTEN ADC_ATTEN_DB_12
#define BV_ADC_UNIT ADC_UNIT_2
#define BV_ADC_CHANNEL ADC_CHANNEL_7 // GPIO_8
#define BV_ADC_BITWIDTH SOC_ADC_DIGI_MAX_BITWIDTH
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

// #define PWM_INIT_DUTY_CYCLE 0
// #define PWM_RESOLUTION 10

adc_continuous_handle_t handle = NULL;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
adc_continuous_handle_t handle = NULL;
static adc_continuous_handle_t handle;

This will automatically be set to NULL if we don't initialize it as a global variable. I'd also change the handle to be static so that we don't pollute the global symbol table.

.conv_frame_size = FRAME_SIZE,
};

ESP_ERROR_CHECK(
Copy link
Member

Choose a reason for hiding this comment

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

Let's get rid of the ESP_ERROS_CHECK() macros and instead create an error variable for the return value and set a flag if initialization failed and report that over CAN. We can then extend this CAN signal to just be the ADC status by using an enum. Take inspiration from eeprom_read().

Co-authored-by: Jacob Koziej <jacobkoziej@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants