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
32 changes: 32 additions & 0 deletions rm_gazebo/launch/series_legged_world.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<launch>
<arg name="robot_type" default="$(env ROBOT_TYPE)" doc="Robot type [standard, auto, hero, engineer]"/>

<arg name="x_pos" default="0.0"/>
<arg name="y_pos" default="0.0"/>
<arg name="z_pos" default="0.0"/>

<arg name="load_chassis" default="true"/>
<arg name="load_gimbal" default="true"/>
<arg name="load_shooter" default="true"/>
<arg name="load_arm" default="true"/>
<arg name="paused" default="false"/>

<rosparam file="$(find rm_gazebo)/config/imus.yaml" command="load" if="$(arg load_gimbal)"/>
<param name="robot_description" command="$(find xacro)/xacro $(find rm_description)/urdf/$(arg robot_type)/$(arg robot_type).urdf.xacro
load_chassis:=$(arg load_chassis) load_gimbal:=$(arg load_gimbal) load_shooter:=$(arg load_shooter)
load_arm:=$(arg load_arm)
use_simulation:=true roller_type:=simple
"/>

<include file="$(find gazebo_ros)/launch/empty_world.launch">
<arg name="world_name" value="$(find rm_gazebo)/worlds/series_legged.world"/>
<arg name="paused" value="false"/>
<arg name="use_sim_time" value="true"/>r
<arg name="gui" value="true"/>
Comment on lines +21 to +25
</include>

<!-- push robot_description to factory and spawn robot in gazebo -->
<node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" clear_params="true"
args="-z 0.5 -param robot_description -urdf -model $(arg robot_type)" output="screen"/>

</launch>
Binary file added rm_gazebo/worlds/place/series_legged_world.stl
Binary file not shown.
73 changes: 73 additions & 0 deletions rm_gazebo/worlds/series_legged.world
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" ?>

<sdf version="1.5">
<world name="default">
<!-- Target real time factor is the product of max_step_size and real_time_update_rate -->
<!-- Negative real_time_update_rate means that Gazebo will run as fast as possible -->
<physics type="ode">
<!-- <type>world</type>-->
<max_step_size>0.001</max_step_size>
<real_time_update_rate>1000</real_time_update_rate>
</physics>

<include>
<uri>model://ground_plane</uri>
</include>

<light name='sun' type='directional'>
<cast_shadows>1</cast_shadows>
<pose>0 0 10 0 -0 0</pose>
<diffuse>0.8 0.8 0.8 1</diffuse>
<specular>0.2 0.2 0.2 1</specular>
<attenuation>
<range>1000</range>
<constant>0.9</constant>
<linear>0.01</linear>
<quadratic>0.001</quadratic>
</attenuation>
<direction>-0.5 0.1 -0.9</direction>
</light>

<model name='series_legged_world'>
<static>1</static>
<static>1</static>
<link name='series_legged_world_link'>
Comment on lines +31 to +34
<pose>-2 -0.6 0.0 0 0 0</pose>
<visual name='visual'>
Comment on lines +31 to +36
<geometry>
<mesh>
<uri>model://rm_gazebo/worlds/place/series_legged_world.stl</uri>
<scale>1 1 1</scale>
</mesh>
</geometry>
</visual>
<collision name='collision'>
<geometry>
<mesh>
<uri>model://rm_gazebo/worlds/place/series_legged_world.stl</uri>
<scale>1 1 1</scale>
</mesh>
</geometry>
<max_contacts>10</max_contacts>
<surface>
<bounce/>
<friction>
<ode/>
</friction>
<contact>
<ode/>
</contact>
</surface>
</collision>
<velocity_decay>
<linear>0</linear>
<angular>0</angular>
</velocity_decay>
<self_collide>0</self_collide>
<kinematic>0</kinematic>
<gravity>1</gravity>
</link>
<static>1</static>
</model>
Comment on lines +70 to +71
Comment on lines +68 to +71
</world>
</sdf>
5 changes: 5 additions & 0 deletions rm_referee/include/rm_referee/referee_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <rm_common/ros_utilities.h>
#include <rm_common/decision/command_sender.h>
#include <vector>
#include <ros/timer.h>
#include <std_msgs/Int32.h>
#include <std_msgs/Float32MultiArray.h>
Expand Down Expand Up @@ -59,6 +60,7 @@ class RefereeBase
virtual void trackCallBack(const rm_msgs::TrackDataConstPtr& data);
virtual void deployDistanceCallBack(const geometry_msgs::PointConstPtr& data);
virtual void balanceStateCallback(const rm_msgs::BalanceStateConstPtr& data);
virtual void leggedChassisStatusCallback(const rm_msgs::LeggedChassisStatusConstPtr& data);
virtual void radarReceiveCallback(const rm_msgs::ClientMapReceiveData::ConstPtr& data);
virtual void mapSentryCallback(const rm_msgs::MapSentryDataConstPtr& data);
virtual void sentryAttackingTargetCallback(const rm_msgs::SentryAttackingTargetConstPtr& data);
Expand Down Expand Up @@ -94,6 +96,7 @@ class RefereeBase
ros::Subscriber track_sub_;
ros::Subscriber deploy_distance_sub_;
ros::Subscriber balance_state_sub_;
ros::Subscriber legged_chassis_status_sub_;
ros::Subscriber radar_receive_sub_;
ros::Subscriber map_sentry_sub_;
ros::Subscriber sentry_to_referee_sub_;
Expand Down Expand Up @@ -125,6 +128,7 @@ class RefereeBase
RotationTimeChangeUi* rotation_time_change_ui_{};
LaneLineTimeChangeGroupUi* lane_line_time_change_ui_{};
BalancePitchTimeChangeGroupUi* balance_pitch_time_change_group_ui_{};
std::vector<LegThetaTimeChangeGroupUi*> leg_theta_time_change_group_uis_{};
PitchAngleTimeChangeUi* pitch_angle_time_change_ui_{};
ImageTransmissionAngleTimeChangeUi* image_transmission_angle_time_change_ui_{};
JointPositionTimeChangeUi *engineer_joint1_time_change_ui{}, *engineer_joint2_time_change_ui{},
Expand All @@ -149,6 +153,7 @@ class RefereeBase
ExceedBulletSpeedFlashUi* exceed_bullet_speed_flash_ui_{};
CustomizeDisplayFlashUi* customize_display_flash_ui_{};
BurstFlashUi* burst_flash_ui_{};
CapacityRunOutFlashUi* capacity_run_out_flash_ui_{};

InteractiveSender* interactive_data_sender_{};
CustomInfoSender* custom_info_sender{};
Expand Down
55 changes: 55 additions & 0 deletions rm_referee/include/rm_referee/ui/flash_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "rm_referee/ui/ui_base.h"

#include <rm_msgs/PowerManagementSampleAndStatusData.h>

namespace rm_referee
{
class FlashUi : public UiBase
Expand Down Expand Up @@ -172,4 +174,57 @@ class BurstFlashUi : public FlashUi
void display(const ros::Time& time) override;
ros::Time start_burst_time_;
};

class CapacityRunOutFlashUi : public FlashUi
{
public:
explicit CapacityRunOutFlashUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue)
: FlashUi(rpc_value, base, "capacity_run_out", graph_queue, character_queue)
{
// Defaults assume capacity_remain_charge is normalized to [0, 1].
threshold_low_ = 0.2;
threshold_high_ = 0.4;
if (rpc_value.hasMember("data"))
{
XmlRpc::XmlRpcValue& data = rpc_value["data"];
try
{
if (data.hasMember("threshold_low"))
threshold_low_ = static_cast<double>(data["threshold_low"]);
if (data.hasMember("threshold_high"))
threshold_high_ = static_cast<double>(data["threshold_high"]);
if (data.hasMember("threshold"))
{
threshold_low_ = static_cast<double>(data["threshold"]);
threshold_high_ = threshold_low_;
}
}
catch (XmlRpc::XmlRpcException&)
{
// Keep defaults.
}
}
if (threshold_high_ < threshold_low_)
threshold_high_ = threshold_low_;

// Warning text should be configured via YAML (config.content).
if (!rpc_value.hasMember("config") || !rpc_value["config"].hasMember("start_position"))
{
// Screen center-ish and slightly upper.
graph_->setStartX(760);
graph_->setStartY(320);
}
}

void updateCapacityData(const rm_msgs::PowerManagementSampleAndStatusData& data, const ros::Time& last_get_data_time);

private:
void display(const ros::Time& time) override;

double threshold_low_{ 0.20 };
double threshold_high_{ 0.30 };
bool low_state_{ false };
bool has_state_{ false };
};
} // namespace rm_referee
139 changes: 139 additions & 0 deletions rm_referee/include/rm_referee/ui/time_change_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#include "rm_referee/ui/ui_base.h"

#include <rm_msgs/LeggedChassisStatus.h>

#include <algorithm>

Comment on lines +9 to +12
namespace rm_referee
{
class TimeChangeUi : public UiBase
Expand Down Expand Up @@ -449,4 +453,139 @@ class TargetHpTimeChangeUi : public TimeChangeUi
int target_hp_{}, target_id_{};
};

class LegThetaTimeChangeGroupUi : public TimeChangeGroupUi
{
public:
explicit LegThetaTimeChangeGroupUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue)
: TimeChangeGroupUi(rpc_value, base, "leg_theta", graph_queue, character_queue)
{
XmlRpc::XmlRpcValue line_config;
line_config["type"] = "line";
if (rpc_value.hasMember("config") && rpc_value["config"].hasMember("color"))
line_config["color"] = rpc_value["config"]["color"];
else
line_config["color"] = "cyan";
if (rpc_value.hasMember("config") && rpc_value["config"].hasMember("width"))
line_config["width"] = rpc_value["config"]["width"];
else
line_config["width"] = 2;
if (rpc_value.hasMember("config") && rpc_value["config"].hasMember("delay"))
line_config["delay"] = rpc_value["config"]["delay"];
else
line_config["delay"] = 0.2;

// Virtual rod is rendered as multiple short segments (dash effect).
XmlRpc::XmlRpcValue virtual_rod_config = line_config;
if (rpc_value.hasMember("config") && rpc_value["config"].hasMember("virtual_rod_color"))
virtual_rod_config["color"] = rpc_value["config"]["virtual_rod_color"];
if (rpc_value.hasMember("config") && rpc_value["config"].hasMember("virtual_rod_width"))
virtual_rod_config["width"] = rpc_value["config"]["virtual_rod_width"];
else
virtual_rod_config["width"] = 1;

Comment on lines +478 to +486
XmlRpc::XmlRpcValue rect_config;
rect_config["type"] = "rectangle";
if (rpc_value.hasMember("config") && rpc_value["config"].hasMember("chassis_color"))
rect_config["color"] = rpc_value["config"]["chassis_color"];
else
rect_config["color"] = line_config["color"];
rect_config["width"] = line_config["width"];
rect_config["delay"] = line_config["delay"];

if (rpc_value.hasMember("data"))
{
XmlRpc::XmlRpcValue data = rpc_value["data"];
if (data.hasMember("draw_chassis"))
draw_chassis_ = static_cast<bool>(data["draw_chassis"]);
if (data.hasMember("chassis_start") && data.hasMember("chassis_end"))
{
chassis_start_[0] = static_cast<int>(data["chassis_start"][0]);
chassis_start_[1] = static_cast<int>(data["chassis_start"][1]);
chassis_end_[0] = static_cast<int>(data["chassis_end"][0]);
chassis_end_[1] = static_cast<int>(data["chassis_end"][1]);
}
else
{
ROS_WARN("LegThetaTimeChangeGroupUi: 'data.chassis_start/end' not defined, using default rectangle.");
chassis_start_[0] = 800;
chassis_start_[1] = 600;
chassis_end_[0] = 1120;
chassis_end_[1] = 720;
}

if (data.hasMember("origin_point"))
{
origin_point_[0] = static_cast<int>(data["origin_point"][0]);
origin_point_[1] = static_cast<int>(data["origin_point"][1]);
}
else
{
// Default: rectangle center.
origin_point_[0] = (chassis_start_[0] + chassis_end_[0]) / 2;
origin_point_[1] = (chassis_start_[1] + chassis_end_[1]) / 2;
}

if (data.hasMember("link1_length"))
link1_length_m_ = static_cast<double>(data["link1_length"]);
if (data.hasMember("link2_length"))
link2_length_m_ = static_cast<double>(data["link2_length"]);
if (data.hasMember("pixels_per_meter"))
pixels_per_meter_ = static_cast<double>(data["pixels_per_meter"]);
if (data.hasMember("leg_side"))
leg_side_ = static_cast<std::string>(data["leg_side"]);
}
else
{
ROS_WARN("LegThetaTimeChangeGroupUi config 's member 'data' not defined.");
}

// Chassis rectangle (left=rear, right=front).
if (draw_chassis_)
{
rect_config["start_position"][0] = chassis_start_[0];
rect_config["start_position"][1] = chassis_start_[1];
rect_config["end_position"][0] = chassis_end_[0];
rect_config["end_position"][1] = chassis_end_[1];
graph_vector_.insert(std::make_pair<std::string, Graph*>("chassis", new Graph(rect_config, base_, id_++)));
}

// Link 1 and Link 2.
line_config["start_position"][0] = origin_point_[0];
line_config["start_position"][1] = origin_point_[1];
line_config["end_position"][0] = origin_point_[0];
line_config["end_position"][1] = origin_point_[1];
graph_vector_.insert(std::make_pair<std::string, Graph*>("link1", new Graph(line_config, base_, id_++)));
graph_vector_.insert(std::make_pair<std::string, Graph*>("link2", new Graph(line_config, base_, id_++)));
}

void calculatePointPosition(const rm_msgs::LeggedChassisStatusConstPtr& data, const ros::Time& time);

private:
void updateConfig() override;

int chassis_start_[2]{ 800, 600 };
int chassis_end_[2]{ 1120, 720 };
int origin_point_[2]{ 960, 660 }; // hip/pivot point in screen coordinates

bool draw_chassis_{ true };

// IK config
double link1_length_m_{ 0.21 };
double link2_length_m_{ 0.248 };
double pixels_per_meter_{ 600.0 };
std::string leg_side_{ "left" }; // "left" or "right"

// Latest input (virtual rod)
double virtual_rod_length_m_{ 0.0 };
double virtual_rod_theta_rad_{ 0.0 };

// Solved points (screen coordinates)
int knee_point_[2]{ 960, 660 };
int foot_point_[2]{ 960, 660 };

// Keep IK solution continuous across updates (avoid knee flipping between the two possible IK branches).
bool knee_initialized_{ false };
};

} // namespace rm_referee
2 changes: 1 addition & 1 deletion rm_referee/src/referee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void Referee::read()
return;
uint8_t temp_buffer[256] = { 0 };
int frame_len;
if (ros::Time::now() - last_get_data_time_ > ros::Duration(0.1))
if (ros::Time::now() - last_get_data_time_ > ros::Duration(5.0))
base_.referee_data_is_online_ = false;
Comment on lines +53 to 54
if (rx_len_ < k_unpack_buffer_length_)
{
Expand Down
Loading
Loading