Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.
Merged

Dev #73

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c5d1142
Rename InstrumentCluster to InstrumentClusterApp and refactor light p…
Rui-Pedro-Pires Jan 17, 2025
cb08ae3
Refactor LightStatus struct by removing Q_PROPERTY macros and update …
Rui-Pedro-Pires Jan 17, 2025
a7a6b62
background change
ziliolu Jan 17, 2025
5cc917b
Refactor InstrumentCluster to use BatteryStatus struct and update lig…
Rui-Pedro-Pires Jan 17, 2025
6f9476e
image change
ziliolu Jan 17, 2025
9ffe7bd
blinkers setup
ziliolu Jan 17, 2025
8088b7d
Refactor UI components to improve light status handling and adjust sp…
Rui-Pedro-Pires Jan 17, 2025
c87b140
Refactor UI components to enhance gear shift display and turn signal …
Rui-Pedro-Pires Jan 20, 2025
68f8158
Refactor turn signal components to separate left and right signals an…
Rui-Pedro-Pires Jan 20, 2025
dd5fd48
Calculate and publish battery percentage based on voltage readings
Rui-Pedro-Pires Jan 20, 2025
40692c9
Remove submodule for Team02-Libs and update CMakeLists to fetch conte…
Rui-Pedro-Pires Jan 20, 2025
a5d303e
Refactor InstrumentCluster to use int for battery status instead of B…
Rui-Pedro-Pires Jan 20, 2025
6d5c398
Refactor CMakeLists and main application; update battery handling to …
Rui-Pedro-Pires Jan 21, 2025
5dd62fe
Refactor gear handling in InstrumentCluster; update QML bindings for …
Rui-Pedro-Pires Jan 21, 2025
a594d25
Remove unused import path for LightInfo.qml in main application
Rui-Pedro-Pires Jan 21, 2025
29ae6c9
Refactor GearPosition to a struct with Q_PROPERTY for better QML inte…
Rui-Pedro-Pires Jan 21, 2025
f8a2af1
Merge pull request #68 from SEAME-pt/66-task-add-the-lights-and-gear-…
Rui-Pedro-Pires Jan 21, 2025
a756d2a
lights blinking
ziliolu Jan 21, 2025
c5e899e
car image
ziliolu Jan 21, 2025
06ba764
Add middleware configuration and update InstrumentCluster to use JSON…
Rui-Pedro-Pires Jan 21, 2025
083a3e1
Refactor InstrumentCluster to support configuration file input; updat…
Rui-Pedro-Pires Jan 21, 2025
5754a49
dealing with lights
ziliolu Jan 22, 2025
a96f28a
Enhance main application to support command-line configuration file i…
Rui-Pedro-Pires Jan 22, 2025
635eabc
Add clock icon to TimeInfo, adjust spacing in multiple QML files, and…
ziliolu Jan 22, 2025
b7e8b4e
Add publishers for lights and gear in main application; implement pub…
Rui-Pedro-Pires Jan 23, 2025
8af81e3
Fix publishing logic for lights and gear to use std::to_string for pr…
Rui-Pedro-Pires Jan 23, 2025
66a6845
Refactor publishing logic to improve debug output and handle light an…
Rui-Pedro-Pires Jan 23, 2025
47a936e
Fix gear data handling in publishing logic to use char type and corre…
Rui-Pedro-Pires Jan 24, 2025
7e93c1b
Merge pull request #72 from SEAME-pt/middleWare-zenoh-config-file-add
Rui-Pedro-Pires Feb 24, 2025
7ea14f8
Merge branch 'dev' into 35-task-qt-fully-functional-ui-app-display
ziliolu Feb 24, 2025
3a39096
Merge pull request #71 from SEAME-pt/35-task-qt-fully-functional-ui-a…
ziliolu Feb 24, 2025
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
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

include_directories(include)

# Add Resource File (QML and Other Resources)
qt_add_resources(QT_RESOURCES ./ui/resources.qrc)

# Define Executable Target
add_executable(InstrumentCluster
add_executable(InstrumentClusterApp
${QT_RESOURCES}
./src/main.cpp
./src/InstrumentCluster.cpp
./include/InstrumentCluster.hpp
)

target_link_libraries(InstrumentCluster zenohcxx::zenohc -lm -ldl Qt6::Core Qt6::DBus Qt6::Quick)
target_link_libraries(InstrumentClusterApp zenohcxx::zenohc -lm -ldl Qt6::Core Qt6::DBus Qt6::Quick)
16 changes: 14 additions & 2 deletions MiddleWare/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,20 @@ set(zenohcxx_DIR "/usr/local/lib/cmake/zenohcxx")
find_package(zenohc REQUIRED)
find_package(zenohcxx REQUIRED)

add_executable(middleWare
# include(FetchContent)
# FetchContent_Declare(
# Libs
# GIT_REPOSITORY https://github.com/SEAME-pt/Team02-Libs
# GIT_TAG main
# )
# FetchContent_MakeAvailable(Libs)

# include_directories(${libs_SOURCE_DIR}/Communication/I2C/include)
# include_directories(${libs_SOURCE_DIR}/Communication/CAN/include)
# include_directories(${libs_SOURCE_DIR}/Peripherals/INA219/include)

add_executable(MiddleWareApp
./src/main.cpp
)

target_link_libraries(middleWare PRIVATE zenohcxx::zenohc)
target_link_libraries(MiddleWareApp PRIVATE zenohcxx::zenohc)
1 change: 0 additions & 1 deletion MiddleWare/Libs
Submodule Libs deleted from 7f38a6
17 changes: 17 additions & 0 deletions MiddleWare/config/MiddleWareConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"mode": "peer",
"connect": {
"endpoints": ["tcp/127.0.0.1:7447"]
},
"listen": {
"endpoints": ["tcp/127.0.0.1:7448"]
},
"scouting": {
"multicast": {
"enabled": false
},
"gossip": {
"enabled": false
}
}
}
50 changes: 43 additions & 7 deletions MiddleWare/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ int main(int argc, char** argv)
std::cout << "CAN socket bound to can0 interface successfully."
<< std::endl;

Config config = Config::create_default();
auto session = Session::open(std::move(config));
auto config = Config::create_default();
if (argc == 2)
{
config = Config::from_file(argv[1]);
}
auto session = Session::open(std::move(config));

auto pubSpeed =
session.declare_publisher(KeyExpr("seame/car/1/speedSensor"));
auto pubBattery =
session.declare_publisher(KeyExpr("seame/car/1/batterySensor"));
auto pubLights = session.declare_publisher(KeyExpr("seame/car/1/lights"));
auto pubGear = session.declare_publisher(KeyExpr("seame/car/1/gear"));

while (1)
{
Expand All @@ -67,19 +73,49 @@ int main(int argc, char** argv)
speed = wheelDiame * 3.14 * speed * 10 / 60;
std::string speed_str = std::to_string(speed);

printf("Publishing speed: '%d'\n", speed);
// printf("Publishing speed: '%d'\n", speed);
pubSpeed.put(speed_str.c_str());
}
else if (frame.can_id == 0x02)
{
int battery;
memcpy(&battery, frame.data, sizeof(int));
battery = ntohl(battery);
double battery;

memcpy(&battery, frame.data, sizeof(double));

float percentage = ((battery - 9.5f) / (12.6f - 9.5f)) * 100.0f;
battery = std::min(100.0f, std::max(0.0f, percentage));
std::string battery_str = std::to_string(battery);

printf("Publishing battery: '%d\n", battery);
// printf("Publishing battery: '%lf\n", battery);
pubBattery.put(battery_str.c_str());
}
else if (frame.can_id == 0x03)
{
char lights;

memcpy(&lights, frame.data, sizeof(char));

printf("Can received lights: ");
for (int i = 7; i >= 0; i--)
{
printf("%d", (lights >> i) & 0x01);
}
printf("\n");

// printf("Publishing lights: '%lf\n", lights[0]);
std::string light_str(1, lights);
pubLights.put(light_str);
}
else if (frame.can_id == 0x04)
{
char gear;

memcpy(&gear, frame.data, sizeof(char));

// printf("Publishing gear: '%lf\n", gear[0]);
std::string gear_str(1, gear);
pubGear.put(std::to_string(gear_str));
}
usleep(10);
}
return 0;
Expand Down
Binary file added assets/icons/cloud.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 assets/icons/watch.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 assets/images/car.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions config/InstrumentClusterConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"mode": "peer",
"connect": {
"endpoints": []
},
"listen": {
"endpoints": ["tcp/127.0.0.1:7447"]
},
"scouting": {
"multicast": {
"enabled": false
},
"gossip": {
"enabled": false
}
}
}
154 changes: 92 additions & 62 deletions include/InstrumentCluster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,90 +7,120 @@

using namespace zenoh;

class InstrumentCluster : public QObject
struct LightStatus
{
Q_OBJECT
Q_PROPERTY(int speed READ getSpeed NOTIFY speedChanged)
Q_PROPERTY(int battery READ getBattery NOTIFY batteryChanged)
Q_PROPERTY(
bool rightBlinker READ getRightBlinker NOTIFY rightBlinkerChanged)
Q_PROPERTY(bool leftBlinker READ getLeftBlinker NOTIFY leftBlinkerChanged)
Q_PROPERTY(bool lowBeam READ getLowBeam NOTIFY lowBeamChanged)
Q_PROPERTY(bool highBeam READ getHighBeam NOTIFY highBeamChanged)
Q_PROPERTY(
bool frontFogLight READ getFrontFogLight NOTIFY frontFogLightChanged)
Q_PROPERTY(
bool readFogLight READ getRearFogLight NOTIFY rearFogLightChanged)
Q_PROPERTY(bool hazardLight READ getHazardLight NOTIFY hazardLightChanged)
Q_PROPERTY(
bool parkingLight READ getParkingLight NOTIFY parkingLightChanged)
Q_PROPERTY(GearPosition gear READ getGear NOTIFY gearChanged)
Q_GADGET

Q_PROPERTY(bool rightBlinker MEMBER rightBlinker)
Q_PROPERTY(bool leftBlinker MEMBER leftBlinker)
Q_PROPERTY(bool lowBeam MEMBER lowBeam)
Q_PROPERTY(bool highBeam MEMBER highBeam)
Q_PROPERTY(bool frontFogLight MEMBER frontFogLight)
Q_PROPERTY(bool rearFogLight MEMBER rearFogLight)
Q_PROPERTY(bool hazardLight MEMBER hazardLight)
Q_PROPERTY(bool parkingLight MEMBER parkingLight)

public:
bool rightBlinker{false};
bool leftBlinker{false};
bool lowBeam{false};
bool highBeam{false};
bool frontFogLight{false};
bool rearFogLight{false};
bool hazardLight{false};
bool parkingLight{false};

bool operator!=(const LightStatus& lights) const
{
return rightBlinker != lights.rightBlinker ||
leftBlinker != lights.leftBlinker || lowBeam != lights.lowBeam ||
highBeam != lights.highBeam ||
frontFogLight != lights.frontFogLight ||
rearFogLight != lights.rearFogLight ||
hazardLight != lights.hazardLight ||
parkingLight != lights.parkingLight;
}
};

struct BatteryStatus
{
Q_GADGET

Q_PROPERTY(int percentage MEMBER percentage)
Q_PROPERTY(int autonomy MEMBER autonomy)

public:
int percentage;
int autonomy;

bool operator!=(const BatteryStatus& battery) const
{
return percentage != battery.percentage || autonomy != battery.autonomy;
}
};

struct GearPosition
{
Q_GADGET

Q_PROPERTY(bool park MEMBER park)
Q_PROPERTY(bool reverse MEMBER reverse)
Q_PROPERTY(bool neutral MEMBER neutral)
Q_PROPERTY(bool drive MEMBER drive)

public:
enum class GearPosition
bool park{true};
bool reverse{false};
bool neutral{false};
bool drive{false};

bool operator!=(const GearPosition& gear) const
{
PARK,
REVERSE,
NEUTRAL,
DRIVE
};
return park != gear.park || reverse != gear.reverse ||
neutral != gear.neutral || drive != gear.drive;
}
};

Q_ENUM(GearPosition)
class InstrumentCluster : public QObject
{
Q_OBJECT
Q_PROPERTY(int speed READ getSpeed NOTIFY speedChanged)
Q_PROPERTY(BatteryStatus battery READ getBattery NOTIFY batteryChanged)
Q_PROPERTY(LightStatus lights READ getLights NOTIFY lightsChanged)
Q_PROPERTY(GearPosition gear READ getGear NOTIFY gearChanged)

private:
int m_speed;
int m_battery;
bool m_rightBlinker;
bool m_leftBlinker;
bool m_lowBeam;
bool m_highBeam;
bool m_frontFogLight;
bool m_rearFogLight;
bool m_hazardLight;
bool m_parkingLight;
BatteryStatus m_battery;
LightStatus m_lights;
GearPosition m_gear;

Session& m_session;
Session m_session;
Subscriber<void> m_subSpeed;
Subscriber<void> m_subBattery;
Subscriber<void> m_subLights;
Subscriber<void> m_subGear;

public:
explicit InstrumentCluster(Session& session, QObject* parent = nullptr);
explicit InstrumentCluster(QObject* parent = nullptr);
explicit InstrumentCluster(const std::string& configFile,
QObject* parent = nullptr);
~InstrumentCluster();

int getSpeed() const;
int getBattery() const;
bool getRightBlinker() const;
bool getLeftBlinker() const;
bool getLowBeam() const;
bool getHighBeam() const;
bool getFrontFogLight() const;
bool getRearFogLight() const;
bool getHazardLight() const;
bool getParkingLight() const;
BatteryStatus getBattery() const;
LightStatus getLights() const;
GearPosition getGear() const;

void setSpeed(int speed);
void setBattery(int battery);
void setRightBlinker(bool rightBlinker);
void setLeftBlinker(bool leftBlinker);
void setLowBeam(bool lowBeam);
void setHighBeam(bool highBeam);
void setFrontFogLight(bool frontFogLight);
void setRearFogLight(bool readFogLight);
void setHazardLight(bool hazardLight);
void setParkingLight(bool parkingLight);
void setBattery(BatteryStatus battery);
void setLights(LightStatus lights);
void setGear(GearPosition gear);

signals:
void speedChanged(int speed);
void batteryChanged(int battery);
void rightBlinkerChanged(bool rightBlinker);
void leftBlinkerChanged(bool leftBlinker);
void lowBeamChanged(bool lowBeam);
void highBeamChanged(bool highBeam);
void frontFogLightChanged(bool frontFogLight);
void rearFogLightChanged(bool readFogLight);
void hazardLightChanged(bool hazardLight);
void parkingLightChanged(bool parkingLight);
void batteryChanged(BatteryStatus battery);
void lightsChanged(LightStatus lights);
void gearChanged(GearPosition gear);
};

Expand Down
Loading