-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
514 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import os | ||
from xacro import process_file | ||
from launch import LaunchDescription | ||
from launch_ros.actions import Node | ||
from ament_index_python.packages import get_package_share_directory | ||
from launch.actions import IncludeLaunchDescription, RegisterEventHandler | ||
from launch.launch_description_sources import PythonLaunchDescriptionSource | ||
from launch.event_handlers import OnProcessExit | ||
|
||
|
||
def generate_launch_description(): | ||
pkg_urc_bringup = get_package_share_directory("urc_bringup") | ||
|
||
controller_config_file_dir = os.path.join( | ||
pkg_urc_bringup, "config", "controller_config.yaml" | ||
) | ||
xacro_file = os.path.join( | ||
get_package_share_directory("urc_hw_description"), "urdf/walli.xacro" | ||
) | ||
assert os.path.exists(xacro_file), "urdf path doesnt exist in " + str(xacro_file) | ||
robot_description_config = process_file( | ||
xacro_file, mappings={"use_simulation": "false"} | ||
) | ||
robot_desc = robot_description_config.toxml() | ||
|
||
control_node = Node( | ||
package="controller_manager", | ||
executable="ros2_control_node", | ||
parameters=[controller_config_file_dir, {"robot_description": robot_desc}], | ||
output="both", | ||
) | ||
|
||
load_status_light_controller = Node( | ||
package="controller_manager", | ||
executable="spawner", | ||
arguments=["-p", controller_config_file_dir, "status_light_controller"], | ||
) | ||
|
||
bt_launch = IncludeLaunchDescription( | ||
PythonLaunchDescriptionSource( | ||
os.path.join(pkg_urc_bringup, "launch", "bt.launch.py") | ||
) | ||
) | ||
|
||
return LaunchDescription( | ||
[ | ||
control_node, | ||
load_status_light_controller, | ||
RegisterEventHandler( | ||
event_handler=OnProcessExit( | ||
target_action=load_status_light_controller, | ||
on_exit=[bt_launch], | ||
) | ||
), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<root BTCPP_format="4"> | ||
<BehaviorTree ID="test_status_light"> | ||
<RunOnce then_skip="true"> | ||
<Sequence> | ||
<Delay delay_msec="100"> | ||
<StatusLightPublisher topic_name="/command/status_light" | ||
color="red" | ||
state="blink"/> | ||
</Delay> | ||
<Delay delay_msec="100"> | ||
<StatusLightPublisher topic_name="/command/status_light" | ||
color="red" | ||
state="off"/> | ||
</Delay> | ||
<Delay delay_msec="100"> | ||
<StatusLightPublisher topic_name="/command/status_light" | ||
color="green" | ||
state="blink"/> | ||
</Delay> | ||
<Delay delay_msec="100"> | ||
<StatusLightPublisher topic_name="/command/status_light" | ||
color="green" | ||
state="off"/> | ||
</Delay> | ||
<Delay delay_msec="100"> | ||
<StatusLightPublisher topic_name="/command/status_light" | ||
color="blue" | ||
state="blink"/> | ||
</Delay> | ||
<Delay delay_msec="100"> | ||
<StatusLightPublisher topic_name="/command/status_light" | ||
color="blue" | ||
state="off"/> | ||
</Delay> | ||
</Sequence> | ||
</RunOnce> | ||
</BehaviorTree> | ||
|
||
<!-- Description of Node Models (used by Groot) --> | ||
<TreeNodesModel> | ||
<Action ID="StatusLightPublisher" | ||
editable="true"> | ||
<input_port name="topic_name" | ||
default="/command/status_light"/> | ||
<input_port name="color"/> | ||
<input_port name="state"/> | ||
</Action> | ||
</TreeNodesModel> | ||
|
||
</root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 53 additions & 16 deletions
69
urc_bt_nodes/include/urc_bt_nodes/actions/status_light_publisher.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,72 @@ | ||
#ifndef STATUS_LIGHT_PUBLISHER_HPP__ | ||
#define STATUS_LIGHT_PUBLISHER_HPP__ | ||
|
||
#include <string> | ||
|
||
#include "behaviortree_cpp/basic_types.h" | ||
#include "behaviortree_cpp/tree_node.h" | ||
#include "behaviortree_cpp/tree_node.h" | ||
#include "behaviortree_ros2/ros_node_params.hpp" | ||
#include "behaviortree_ros2/bt_topic_pub_node.hpp" | ||
#include "string" | ||
#include "std_msgs/msg/int8.hpp" | ||
|
||
#include "urc_msgs/msg/status_light_command.hpp" | ||
|
||
namespace behavior::actions | ||
{ | ||
class StatusLightPublisher : public BT::RosTopicPubNode<std_msgs::msg::Int8> | ||
{ | ||
public: | ||
StatusLightPublisher( | ||
const std::string & instance_name, const BT::NodeConfig & conf, | ||
const BT::RosNodeParams & params) | ||
: BT::RosTopicPubNode<std_msgs::msg::Int8>(instance_name, conf, params) {} | ||
|
||
static BT::PortsList providedPorts() | ||
int stringToColor(std::string color) | ||
{ | ||
if (color == "red") | ||
{ | ||
return urc_msgs::msg::StatusLightCommand::RED; | ||
} | ||
if (color == "green") | ||
{ | ||
return urc_msgs::msg::StatusLightCommand::GREEN; | ||
} | ||
if (color == "blue") | ||
{ | ||
return urc_msgs::msg::StatusLightCommand::BLUE; | ||
} | ||
|
||
throw std::invalid_argument("Invalid color!"); | ||
} | ||
|
||
int stringToState(std::string state) | ||
{ | ||
return providedBasicPorts( | ||
{ | ||
BT::InputPort<std_msgs::msg::Int8>("value"), | ||
}); | ||
if (state == "on") | ||
{ | ||
return urc_msgs::msg::StatusLightCommand::ON; | ||
} | ||
if (state == "off") | ||
{ | ||
return urc_msgs::msg::StatusLightCommand::OFF; | ||
} | ||
if (state == "blink") | ||
{ | ||
return urc_msgs::msg::StatusLightCommand::BLINK; | ||
} | ||
|
||
throw std::invalid_argument("Invalid state!"); | ||
} | ||
|
||
bool setMessage(std_msgs::msg::Int8 & msg) override; | ||
class StatusLightPublisher : public BT::RosTopicPubNode<urc_msgs::msg::StatusLightCommand> | ||
{ | ||
public: | ||
StatusLightPublisher( | ||
const std::string &instance_name, const BT::NodeConfig &conf, | ||
const BT::RosNodeParams ¶ms) | ||
: BT::RosTopicPubNode<urc_msgs::msg::StatusLightCommand>(instance_name, conf, params) {} | ||
|
||
static BT::PortsList providedPorts() | ||
{ | ||
return providedBasicPorts( | ||
{BT::InputPort<std::string>("color"), | ||
BT::InputPort<std::string>("state")}); | ||
} | ||
|
||
}; | ||
bool setMessage(urc_msgs::msg::StatusLightCommand &msg) override; | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.