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

Sv 4 battery indicator #9

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

Sv 4 battery indicator #9

wants to merge 11 commits into from

Conversation

ecl1ipse
Copy link

A GUI widget that shows battery percentage.

…cator in the top left corner. When left is pressed, the charge reduces and when right is pressed, the charge increases
… 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
Copy link
Member

@hjed hjed left a 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/resources/main_window.qml Outdated Show resolved Hide resolved
@@ -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);
Copy link
Member

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 {
Copy link
Member

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);
Copy link
Member

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);

}*/
Copy link
Member

Choose a reason for hiding this comment

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

commented code

@@ -82,7 +112,7 @@ Window {


}
}
}*/
Copy link

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
Copy link

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) {
Copy link

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);
Copy link

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
Copy link

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"),
Copy link

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
Copy link

Choose a reason for hiding this comment

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

topic in header

@burrrrrr
Copy link

burrrrrr commented Sep 8, 2018

move battery related code to a new directory ros_battery_indicator with its own package.xml and CMakeLists file

@wmpmiles
Copy link

@ecl1ipse Master has been updated, please re-merge and resolve conflicts.

Copy link
Contributor

@sajidanower23 sajidanower23 left a 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"?>
Copy link
Contributor

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
Copy link
Contributor

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);
Copy link
Contributor

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;
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation is off

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.

None yet

5 participants