-
Notifications
You must be signed in to change notification settings - Fork 3
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
Sv 4 battery indicator #9
base: master
Are you sure you want to change the base?
Conversation
…cator in the top left corner. When left is pressed, the charge reduces and when right is pressed, the charge increases
…howing percentage
… as color changing so changes in battery % are more noticeable
…change to red when the battery % is too high or low
…e creation of the widget to the cpp file to make it work with the subscriber. Indicator should be ready for testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I think you're on the right track with this. Now you need to make the charge
variable a signal so you can use it in your qml code and get the data from ros.
src/gui/src/main_application.cpp
Outdated
@@ -14,6 +15,8 @@ void Main_Application::run() { | |||
qmlRegisterType<Stopwatch>("bluesat.owr", 1, 0, "Stopwatch"); | |||
qmlRegisterType<ROS_Video_Component>("bluesat.owr", 1, 0, "ROSVideoComponent"); | |||
qmlRegisterType<ROS_Signal_Strength>("bluesat.owr", 1, 0, "ROSSignalStrength"); | |||
qmlRegisterType<ROS_Battery_Indicator>("bluesat.owr", 1, 0, "ROSBatteryIndicator"); //added | |||
//qmlRegisterSingletonType<ROS_Battery_Indicator>("bluesat.owr.singleton", 1, 0, "ROSBatterryIndicator", &ros_battery_indicator::qml_instance); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented out code (I think you can delete that)
#include <std_msgs/Float32.h> | ||
|
||
|
||
class ROS_Battery_Indicator: public QQuickPaintedItem { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can probably just extend QQuickItem
as it doesn't need the functionality of QQuickPaintedItem
// Constructor, takes parent widget, which defaults to null | ||
ROS_Battery_Indicator(QQuickItem * parent = 0); | ||
|
||
//void paint(QPainter *painter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented code
int y = 20; | ||
painter->drawRect(x,y,FULL_CHARGE,15); | ||
|
||
}*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented code
Battery indicator should be ready for testing
src/gui/resources/main_window.qml
Outdated
@@ -82,7 +112,7 @@ Window { | |||
|
|||
|
|||
} | |||
} | |||
}*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented code
@@ -40,7 +39,7 @@ class ROS_Battery_Indicator: public QQuickPaintedItem { | |||
QString topic_value; | |||
bool ros_ready; | |||
|
|||
int charge; //the battery charge | |||
float charge; //the battery charge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
|
||
ROS_Battery_Indicator::ROS_Battery_Indicator(QQuickItem * parent) : | ||
QQuickPaintedItem(parent), | ||
topic_value("/rover/signal"), | ||
topic_value("/rover/batttery"), | ||
ros_ready(false), | ||
charge(33) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change this to a percentage out of 100
|
||
char percentage[6]; | ||
charge_p = (charge_p / 33) * 100; | ||
sprintf(percentage, "%d%%", (int) charge_p); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
charge is already a percentage, no need for another variable
|
||
#define RECT_X 10 | ||
#define RECT_Y 10 | ||
#define FULL_CHARGE 33 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FULL_CHARGE is a percentage now (100)
|
||
ROS_Battery_Indicator::ROS_Battery_Indicator(QQuickItem * parent) : | ||
QQuickPaintedItem(parent), | ||
topic_value("/rover/signal"), | ||
topic_value("/rover/batttery"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hash define topic in header
ros_ready(false), | ||
charge(33) { | ||
} | ||
|
||
void ROS_Battery_Indicator::setup(ros::NodeHandle * nh) { | ||
|
||
signal_sub = nh->subscribe( | ||
"/rover/signal", //TODO | ||
"/rover/battery", //TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
topic in header
move battery related code to a new directory ros_battery_indicator with its own package.xml and CMakeLists file |
@ecl1ipse Master has been updated, please re-merge and resolve conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly style changes and consistency issues.
@@ -0,0 +1,308 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this file.
Run git rm qt-gui.workspace.user.865c78c
, commit and push.
@@ -2,6 +2,7 @@ | |||
#include <QDebug> | |||
#include "ros_video_components/ros_video_component.hpp" | |||
#include "ros_video_components/ros_signal_strength.hpp" | |||
#include "ros_video_components/ros_battery_indicator.hpp" //added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need the comment //added
😛
void topic_changed(); | ||
|
||
private: | ||
void receive_signal(const std_msgs::Float32::ConstPtr & msg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
receive_signal
is not a proper variable name here. I named it receive_signal
because it was literally receiving the signal strength of the antenna. For you, it would be something like receive_battery_voltage
.
|
||
// ROS | ||
ros::NodeHandle * nh; | ||
ros::Subscriber signal_sub; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
signal_sub
, again, is not an appropriate name here. I would suggest battery_sub
or something.
QString topic_value; | ||
bool ros_ready; | ||
|
||
float charge; //the battery charge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is off
A GUI widget that shows battery percentage.