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

Feature/battery warning msi laptop #45

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
cmake_minimum_required(VERSION 3.0.2)
project(hero_bringup)

find_package(catkin REQUIRED)
find_package(catkin REQUIRED COMPONENTS
roscpp
sensor_msgs
)

include_directories(${catkin_INCLUDE_DIRS})

catkin_add_env_hooks(99.hero_functions SHELLS bash DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/env-hooks)

catkin_python_setup()

catkin_package()

###########
## Build ##
###########

add_executable(battery_manager_laptop src/battery_manager_laptop.cpp)
add_dependencies(battery_manager_laptop ${catkin_EXPORTED_TARGETS})
target_link_libraries(battery_manager_laptop
${catkin_LIBRARIES}
)
10 changes: 10 additions & 0 deletions launch/battery_manager_hero2.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<launch>
<arg name="namespace" default="/hero" />

<group ns="$(arg namespace)">
<!-- Battery warning parameters -->
<rosparam file="$(find hero_bringup)/parameters/hardware/battery_manager_hero2.yaml" command="load" />
<node name="battery_manager_hero2" pkg="hero_bringup" type="battery_manager_laptop" />
</group>
</launch>
1 change: 0 additions & 1 deletion launch/hero_bringup.launch
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
<include file="$(find robot_launch_files)/launch/interaction/mobile_ui_server.launch" unless="$(optenv ROBOT_REAL false)" />
</group>


<!-- Real hardware -->
<group if="$(optenv ROBOT_REAL false)" >

Expand Down
5 changes: 5 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

<buildtool_depend>catkin</buildtool_depend>

<build_depend>roscpp</build_depend>
<build_depend>sensor_msgs</build_depend>

<exec_depend>gazebo_msgs</exec_depend>
<exec_depend>geometry_msgs</exec_depend>
<exec_depend>hero_bridge</exec_depend>
Expand All @@ -23,6 +26,8 @@
<exec_depend condition="$ROS_PYTHON_VERSION == 2">python-yaml</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 3">python3-yaml</exec_depend>
<exec_depend>robot_launch_files</exec_depend>
<exec_depend>roscpp</exec_depend>
<exec_depend>rospy</exec_depend>
<exec_depend>sensor_msgs</exec_depend>

</package>
4 changes: 4 additions & 0 deletions parameters/hardware/battery_manager_hero2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
robot_location: "hero2"
battery_empty: 10
battery_low: 20
battery_middle: 50
11 changes: 11 additions & 0 deletions scripts/services/hero2-demo/hero2-demo-battery-manager.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=running battery_manager_laptop

[Install]
WantedBy=multi-user.target

[Service]
User=demo
Restart=on-failure
ExecStart=/bin/bash -c 'source /home/demo/.tue/setup.bash && \
roslaunch hero_bringup battery_manager_hero2.launch'
11 changes: 11 additions & 0 deletions scripts/services/hero2/hero2-battery-manager.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=running battery_manager_laptop

[Install]
WantedBy=multi-user.target

[Service]
User=amigo
Restart=on-failure
ExecStart=/bin/bash -c 'source /home/amigo/.tue/setup.bash && \
roslaunch hero_bringup battery_manager_hero2.launch'
75 changes: 75 additions & 0 deletions src/battery_manager_laptop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <ros/ros.h>
#include <sensor_msgs/BatteryState.h>
#include <std_msgs/String.h>
#include <string>
#include <sstream>

int middle;
int low;
int empty;
std::string robot_location = "";
std::string old_message = "";
ros::Publisher speech_pub;

void batteryCallback(const sensor_msgs::BatteryState::ConstPtr& msg)
{
int percentage;
std::string message = "";
std::string location = "";
std::ostringstream string_message;

if (msg->location == robot_location)
{
percentage = (msg->percentage)*100;
location = msg->location;

// check battery status
if (percentage < empty)
KevinDang74 marked this conversation as resolved.
Show resolved Hide resolved
{
string_message << "The battery on" << location << " is at" << percentage << " percent. Charge me now!";
}
else if (percentage < low)
{
string_message << "The battery on" << location << " is at" << percentage << " percent. Don't forget to charge me";
}
else if (percentage < middle)
{
string_message << "The battery on" << location << " is at" << percentage << " percent. Keep an I on the batteries";
}

message = string_message.str();

// publish voice message
if (old_message != message && message != "")
Copy link
Member

Choose a reason for hiding this comment

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

Good to have indeed :-)

Can also be part of the callback though AFAIK

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree. We would want to check whether the percentage has changed rather than the message

{
std_msgs::String speech_msg;
speech_msg.data = message;
speech_pub.publish(speech_msg);
old_message = message;
}
}
}

int main(int argc, char **argv)
{
ros::init(argc, argv, "Battery_manager_laptop");
ros::NodeHandle gn;

ros::param::get("/battery_middle", middle);
ros::param::get("/battery_low", low);
ros::param::get("/battery_empty", empty);
ros::param::get("/robot_location", robot_location);
KevinDang74 marked this conversation as resolved.
Show resolved Hide resolved

ros::Subscriber battery_sub = gn.subscribe("battery", 1, batteryCallback);
speech_pub = gn.advertise<std_msgs::String>("text_to_speech/input", 10);
Copy link
Contributor

Choose a reason for hiding this comment

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

This speech publisher goes to the text to speech bridge node. Please either:

  • publish directly to the toyota interface (my preference)
  • launch the speech bridge along with the battery manager

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How can I publish directly to the toyota interface? What is the topic name?

Copy link
Contributor

Choose a reason for hiding this comment

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


ros::Rate loop_rate(1.0);
KevinDang74 marked this conversation as resolved.
Show resolved Hide resolved

while(gn.ok())
{
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}