Skip to content
Merged
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
9 changes: 4 additions & 5 deletions src/rj_ui/include/rj_ui/processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
#include <optional>
#include <vector>

#include <rclcpp/rclcpp.hpp>
#include <rclcpp_action/rclcpp_action.hpp>

#include <QMutexLocker>
#include <rclcpp/executors/single_threaded_executor.hpp>
#include <rclcpp/rclcpp.hpp>
#include <rclcpp_action/rclcpp_action.hpp>
#include <spdlog/spdlog.h>

#include <rj_common/context.hpp>
Expand Down Expand Up @@ -155,10 +154,10 @@ class Processor {

// ROS2 temporary modules
using WorldStateMsg = rj_msgs::msg::WorldState;

using AsyncWorldStateMsgQueue = rj_topic_utils::AsyncMessageQueue<
WorldStateMsg, rj_topic_utils::MessagePolicy::kQueue, 1>;

// replace this w a sub and callback
// rclcpp::Subscription<WorldState::Msg>::SharedPtr world_state_sub_;
// WorldStateMsg::UniquePtr world_state_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ class RawVisionPacketSub {
using RawProtobufMsgQueue = rj_topic_utils::AsyncMessageQueue<
RawProtobufMsg, rj_topic_utils::MessagePolicy::kQueue>;
RawProtobufMsgQueue::UniquePtr queue_;

};
} // namespace ros2_temp
3 changes: 1 addition & 2 deletions src/rj_ui/src/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ Processor::Processor(bool sim, bool blue_team, const std::string& read_log_file)
[this](WorldStateMsg::UniquePtr msg) {
rj_convert::convert_from_ros(*msg, &context_.world_state);
last_vision_time_ = rj_convert::convert_from_ros(msg->last_update_time);
}
);
});

debug_draw_sub_ =
std::make_unique<ros2_temp::DebugDrawInterface>(&context_, ros_executor_.get());
Expand Down
19 changes: 0 additions & 19 deletions src/rj_vision_filter/include/rj_vision_filter/vision_filter.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#pragma once


#include <atomic>
#include <mutex>
#include <thread>
#include <vector>


#include <rclcpp/rclcpp.hpp>


#include <rj_config_client/config_client.hpp>
#include <rj_msgs/msg/detection_frame.hpp>
#include <rj_msgs/msg/team_color.hpp>
Expand All @@ -18,15 +15,12 @@
#include <rj_topic_utils/message_queue.hpp>
#include <rj_utils/concurrent_queue.hpp>


#include "rj_vision_filter/camera/camera_frame.hpp"
#include "rj_vision_filter/camera/world.hpp"


namespace vision_filter {
using TeamColorMsg = rj_msgs::msg::TeamColor;


/**
* Filters the vision measurements into a smoother velocity/position estimate for both the ball and
* robots.
Expand All @@ -37,13 +31,11 @@ class VisionFilter : public rclcpp::Node {
using RobotStateMsg = rj_msgs::msg::RobotState;
using BallStateMsg = rj_msgs::msg::BallState;


/**
* Initialize the vision filter and all callbacks.
*/
VisionFilter(const rclcpp::NodeOptions& options);


private:
/**
* @brief Creates a WorldStateMsg from the robot and ball Kalman filters.
Expand All @@ -53,15 +45,13 @@ class VisionFilter : public rclcpp::Node {
*/
WorldStateMsg build_world_state_msg(bool us_blue) const;


/**
* @brief Creates a BallStateMsg from the ball Kalman filter.
* @return The BallStateMsg corresponding to the current VisionFilter
* state.
*/
BallStateMsg build_ball_state_msg() const;


/**
* @brief Creates a vector of RobotStateMsgs from the robot Kalman filters.
* @param blue_team Uses the blue team's robots if true. Otherwise uses the
Expand All @@ -70,13 +60,11 @@ class VisionFilter : public rclcpp::Node {
*/
std::vector<RobotStateMsg> build_robot_state_msgs(bool blue_team) const;


/**
* @brief Publishes the current state of the balls and robots.
*/
void publish_state();


// TODO(1562): (It's horrible, but it's only temporary until VisionFilter
// gets refactored).
/**
Expand All @@ -88,7 +76,6 @@ class VisionFilter : public rclcpp::Node {
return defend_plus_x ? -M_PI_2 : M_PI_2;
}


/**
* @brief Returns the transform from the world to the team.
* @return The transform from the world to the team frame.
Expand All @@ -100,34 +87,28 @@ class VisionFilter : public rclcpp::Node {
return world_to_team;
}


/**
* @brief State of the world, ie. robots and ball.
*/
World world_;

config_client::ConfigClient config_client_;


rclcpp::Subscription<TeamColorMsg>::SharedPtr team_color_sub_;
std::atomic<bool> us_blue_{true};


/**
* @brief Timer driving regular publication.
*/
rclcpp::TimerBase::SharedPtr publish_timer_;


rclcpp::Subscription<DetectionFrameMsg>::SharedPtr detection_frame_sub_;


/**
* @brief Publisher for WorldStateMsg.
*/
rclcpp::Publisher<WorldStateMsg>::SharedPtr world_state_pub_;


::params::LocalROS2ParamProvider param_provider_;
};
} // namespace vision_filter
29 changes: 7 additions & 22 deletions src/rj_vision_filter/src/vision_filter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "rj_vision_filter/vision_filter.hpp"


#include <rj_common/time.hpp>
#include <rj_common/world_state.hpp>
#include <rj_constants/constants.hpp>
Expand All @@ -9,13 +8,11 @@
#include <rj_param_utils/vision/vision_params.hpp>
#include <rj_utils/logging_macros.hpp>


namespace vision_filter {
DEFINE_FLOAT64(kVisionFilterParamModule, publish_hz, 60.0,
"The rate in Hz at which VisionFilter publishes ball and robot "
"observations.")


VisionFilter::VisionFilter(const rclcpp::NodeOptions& options)
: rclcpp::Node{"vision_filter", options},
config_client_{this},
Expand All @@ -25,13 +22,12 @@ VisionFilter::VisionFilter(const rclcpp::NodeOptions& options)
auto publish_callback = [this]() { publish_state(); };
publish_timer_ = create_wall_timer(predict_timer_period, publish_callback);


// Create a subscripter for TeamColorMsg
const auto team_color_callback = [this](TeamColorMsg::UniquePtr msg) {us_blue_.store(msg->is_blue); };
team_color_sub_ = create_subscription<TeamColorMsg>(
referee::topics::kTeamColorTopic, rclcpp::QoS(1),
team_color_callback
);
const auto team_color_callback = [this](TeamColorMsg::UniquePtr msg) {
us_blue_.store(msg->is_blue);
};
team_color_sub_ = create_subscription<TeamColorMsg>(referee::topics::kTeamColorTopic,
rclcpp::QoS(1), team_color_callback);

// Create a subscriber for the DetectionFrameMsg
constexpr int kQueueSize = 10;
Expand All @@ -40,7 +36,6 @@ VisionFilter::VisionFilter(const rclcpp::NodeOptions& options)
return;
}


const double current_team_angle = team_angle();
const rj_geometry::TransformMatrix current_world_to_team = world_to_team();
auto frame = CameraFrame(*msg, current_world_to_team, current_team_angle);
Expand All @@ -49,12 +44,10 @@ VisionFilter::VisionFilter(const rclcpp::NodeOptions& options)
detection_frame_sub_ = create_subscription<DetectionFrameMsg>(
vision_receiver::topics::kDetectionFrameTopic, rclcpp::QoS(kQueueSize), callback);


// Create world state publisher
world_state_pub_ = create_publisher<WorldStateMsg>(topics::kWorldStateTopic, 10);
}


VisionFilter::WorldStateMsg VisionFilter::build_world_state_msg(bool us_blue) const {
return rj_msgs::build<WorldStateMsg>()
.last_update_time(rj_convert::convert_to_ros(world_.last_update_time()))
Expand All @@ -63,11 +56,9 @@ VisionFilter::WorldStateMsg VisionFilter::build_world_state_msg(bool us_blue) co
.ball(build_ball_state_msg());
}


VisionFilter::BallStateMsg VisionFilter::build_ball_state_msg() const {
const WorldBall& wb = world_.get_world_ball();


BallStateMsg msg{};
msg.stamp = rj_convert::convert_to_ros(wb.get_time());
msg.position = rj_convert::convert_to_ros(wb.get_pos());
Expand All @@ -76,39 +67,33 @@ VisionFilter::BallStateMsg VisionFilter::build_ball_state_msg() const {
return msg;
}


std::vector<VisionFilter::RobotStateMsg> VisionFilter::build_robot_state_msgs(
bool blue_team) const {
const auto& robots = blue_team ? world_.get_robots_blue() : world_.get_robots_yellow();


// Fill our robots
std::vector<RobotStateMsg> robot_state_msgs(kNumShells);
for (size_t i = 0; i < kNumShells; i++) {
const WorldRobot& wr = robots.at(i);


RobotState robot_state;
robot_state.visible = wr.get_is_valid();


if (wr.get_is_valid()) {
robot_state.pose = rj_geometry::Pose(wr.get_pos(), wr.get_theta());
robot_state.velocity = rj_geometry::Twist(wr.get_vel(), wr.get_omega());
robot_state.timestamp = wr.get_time();
}


robot_state_msgs.at(i) = rj_convert::convert_to_ros(robot_state);
}
return robot_state_msgs;
}


void VisionFilter::publish_state() {
WorldStateMsg::UniquePtr msg = std::make_unique<WorldStateMsg>(build_world_state_msg(us_blue_.load()));
WorldStateMsg::UniquePtr msg =
std::make_unique<WorldStateMsg>(build_world_state_msg(us_blue_.load()));
world_state_pub_->publish(std::move(msg));
}


} // namespace vision_filter