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

Display BackEMF on Display #371

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Display BackEMF on Display #371

wants to merge 6 commits into from

Conversation

jiwoop
Copy link

@jiwoop jiwoop commented Nov 18, 2023

Quality Assurance Checklist

To make reviews more efficient, please make sure the software feature meets the following standards and check everything off that meets the quality check. Once everything has been checked, the assigned reviewers will begin the review process. Edit this description to check off the list.

There are exceptions with all guidelines. As long as your decisions are justified, then you are good! Contact the reviewers or the leads about any exceptions.

Requirements

  • Followed Coding Style Guide
  • Presented/discussed in some capacity with others on the Controls team
  • Code Build checks pass
  • No merge conflicts
  • Software feature has documentation for it updated in both ReadTheDocs and the comments
  • Software feature has documentation for it updated
  • Testing
    • Software feature has test associated with it
    • Test provides useful information and uses relevant data to accurately represent Controls
    • Tested on hardware
    • NOTE: If test file already exists, use that one
  • If applicable, have you added the new feature to main.c?
  • Tagged appropriate issue ticket on this PR
  • Did you have fun?

Things to Consider

  • Even if the above are checked, is this the best way of writing my code?
    • It's possible to write code that works, but are there ways to make code more efficient?

@jiwoop jiwoop linked an issue Nov 18, 2023 that may be closed by this pull request
@jiwoop
Copy link
Author

jiwoop commented Nov 18, 2023

Have been working on this with hardware, currently getting Fault screen when flashed on display. Parts that I've modified are the BackEMF power calculation and display functions.

static float Motor_RPM = CAR_STOPPED; //Car is stopped until velocity is read
static float Motor_Velocity = CAR_STOPPED; //^^^^
static float Motor_RPM = CAR_STOPPED; //Car is stopped until velocity is read
static float Motor_Velocity = CAR_STOPPED; //^^^^
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 do the ^^^^ comment. You can just adjust the first one to say "until velocity and RPM are read"

Comment on lines +110 to +118
memcpy(&Bus_Voltage, &dataBuf.data[0], sizeof(float));
memcpy(&Bus_Current, &dataBuf.data[4], sizeof(float));

//Bus voltage is in bytes 0-4
Bus_Voltage = *((float*)(&dataBuf.data[0]));

//Bus Current is in bytes 4-8
Bus_Current = *((float*)(&dataBuf.data[4]));

Copy link
Member

Choose a reason for hiding this comment

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

Why are you doing both a memcpy and a pointer dereference to copy the values? Are these not redundant?

Imo, just use the memcpy for code clarity.

Comment on lines +126 to +129
memcpy(&Back_EMF, &dataBuf.data[0], sizeof(float)); // BEMFq (The peak of the phase to neutral motor voltage)

//BackEMF is in bytes 0-4
Back_EMF = *((float*)(&dataBuf.data[0]));
Copy link
Member

Choose a reason for hiding this comment

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

Same as above

UpdateDisplay_SetAccel(accelPedalPercent);
UpdateDisplay_SetBackEMF(accelPedalPercent, brakePedalPercent);
Copy link
Member

Choose a reason for hiding this comment

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

is there a reason that you only care abt the backemf and not the accel percent? Just curious

UpdateDisplayError_t ret = UpdateDisplay_SetComponent(MOTOR, percent);
assertUpdateDisplayError(ret);

if(ret == UPDATEDISPLAY_ERR_NONE) lastPercentPower = percent;
Copy link
Member

Choose a reason for hiding this comment

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

out of curiosity, is this if statement actually necessary? Is this not handled by the assert above this?

UpdateDisplayError_t ret = UpdateDisplay_SetComponent(REGEN_METER, percent);
assertUpdateDisplayError(ret);

if(ret == UPDATEDISPLAY_ERR_NONE) lastPercentRegen = percent;
Copy link
Member

Choose a reason for hiding this comment

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

same as above

Comment on lines +340 to +343
void UpdateDisplay_SetBackEMF(uint8_t forwardPercent, int32_t regenPercent) {
UpdateDisplay_SetForwardPower(forwardPercent);
UpdateDisplay_SetRegenPower(regenPercent);
}
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this is nitpicky, but if setting backemf is just a wrapper function for simultaneously setting forward and regen power, I'm not sure that's the best idea. I can definitely see someone trying to manually set forward power / regen power and it getting overwritten by a setbackemf call somewhere.

@IshDeshpa any clarity on why we need a dedicated setter for this?

If we do need it, can it maybe me named more specifically, or given a header comment noting that it shouldn't be used in conjunction with the other two calls. Could also deprecate the other two functions if we want everyone to use this moving forward.

Comment on lines +26 to +61
OSTaskCreate(
(OS_TCB*)&SendTritium_TCB,
(CPU_CHAR*)"SendTritium",
(OS_TASK_PTR)Task_SendTritium,
(void*) NULL,
(OS_PRIO)TASK_SEND_TRITIUM_PRIO,
(CPU_STK*)SendTritium_Stk,
(CPU_STK_SIZE)WATERMARK_STACK_LIMIT/10,
(CPU_STK_SIZE)TASK_SEND_TRITIUM_STACK_SIZE,
(OS_MSG_QTY) 0,
(OS_TICK)NULL,
(void*)NULL,
(OS_OPT)(OS_OPT_TASK_STK_CLR),
(OS_ERR*)&err
);

if (err != OS_ERR_NONE) {
printf("SendTritium Task error code %d\n", err);
}

// ReadTritium
OSTaskCreate(
(OS_TCB*)&ReadTritium_TCB,
(CPU_CHAR*)"ReadTritium",
(OS_TASK_PTR)Task_ReadTritium,
(void*) NULL,
(OS_PRIO)TASK_READ_TRITIUM_PRIO,
(CPU_STK*)SendTritium_Stk,
(CPU_STK_SIZE)WATERMARK_STACK_LIMIT/10,
(CPU_STK_SIZE)TASK_READ_TRITIUM_STACK_SIZE,
(OS_MSG_QTY) 0,
(OS_TICK)NULL,
(void*)NULL,
(OS_OPT)(OS_OPT_TASK_STK_CLR),
(OS_ERR*)&err
);
Copy link
Member

@babusid babusid Dec 13, 2023

Choose a reason for hiding this comment

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

While this is probably functional, idk if its the best approach. IMO, since the only thing that the UpdateDisplay task relies on is something populating the UpdateDisplay application queue, why not just have a test task written in this file that does that?

That way this task isn't coupled to the other two applications, and can be used freely. Keeping the tests isolated from system changes elsewhere makes them more useful, because what happens if we make some breaking changes to ReadTritium or SendTritium? This test could become useless.

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.

Add Back EMF and Percent Power Output to Display
2 participants