ricboard_pub.cpp
Go to the documentation of this file.
1 
2 #include "ricboard_pub.h"
3 
5 {
6  nh_ = &nh;
7 
8  /* get ric params */
9  ros::param::get("~load_ric_hw", load_ric_hw_);
10 
11  if (load_ric_hw_)
12  {
14  {
15  ROS_ERROR("[armadillo2_hw/ricboard_pub]: %s param is missing on param server. make sure that you load this param exist in ricboard_config.yaml "
16  "and that your launch includes this param file. shutting down...", RIC_PORT_PARAM);
17  ros::shutdown();
18  exit (EXIT_FAILURE);
19  }
20 
22  {
23  ROS_ERROR("[armadillo2_hw/ricboard_pub]: %s param is missing on param server. make sure that this param exist in controllers.yaml "
24  "and that your launch includes this param file. shutting down...", TORSO_JOINT_PARAM);
25  ros::shutdown();
26  exit (EXIT_FAILURE);
27  }
28 
29  try{
31  ROS_INFO("[armadillo2_hw/ricboard_pub]: ricboard port opened successfully \nport name: %s \nbaudrate: 115200", ric_port_.c_str());
33  ROS_ERROR("[armadillo2_hw/ricboard_pub]: can't open ricboard port. make sure that ricboard is connected. shutting down...");
34  ros::shutdown();
35  exit(1);
36  }
37 
40 
41  /* ric publishers */
42  ric_gps_pub_ = nh.advertise<sensor_msgs::NavSatFix>("GPS/fix", 10);
43  ric_ultrasonic_pub_ = nh.advertise<sensor_msgs::Range>("URF/front", 10);
44  ric_imu_pub_ = nh.advertise<sensor_msgs::Imu>("IMU", 10);
45 
48  ROS_INFO("[armadillo2_hw/ricboard_pub]: ricboard is up");
49  espeak_pub_ = nh.advertise<std_msgs::String>("/espeak_node/speak_line", 10);
50  /*speakMsg("rik board is up", 1); */
51  }
52  else
53  ROS_WARN("[armadillo2_hw/ricboard_pub]: ric hardware is disabled");
54 }
55 
57 {
58  if (!load_ric_hw_)
59  return;
60  t = new boost::thread(boost::bind(&RicboardPub::loop, this));
61 }
62 
64 {
65  if (!load_ric_hw_)
66  return;
67  t->interrupt();
68 }
69 
71 {
72  if (!load_ric_hw_)
73  return;
74  while (ros::ok() && !t->interruption_requested())
75  {
76  ric_.loop();
77  if (ric_.isBoardAlive())
78  {
82  /* if emergecy pin disconnected, shutdown. ric will also kill torso */
84  {
85  speakMsg("emergency, shutting down", 1);
86  ROS_ERROR("[armadillo2_hw/ricboard_pub]: EMERGENCY PIN DISCONNECTED, shutting down...");
87  ros::shutdown();
88  exit(EXIT_FAILURE);
89  }
90  }
91  else
92  {
95  }
96  }
97 }
98 
100 {
101  if (!load_ric_hw_)
102  return;
105  {
106  speakMsg("rik board disconnected, shutting down", 1);
107  ROS_ERROR("[armadillo2_hw/ricboard_pub]: ricboard disconnected. shutting down...");
108  ros::shutdown();
109  exit(EXIT_FAILURE);
110  }
111 }
112 
114 {
115  if (!load_ric_hw_)
116  return;
117 
119 
120  /* publish ultrasonic */
121  sensor_msgs::Range range_msg;
122  range_msg.header.stamp = ros::Time::now();
123  range_msg.header.frame_id = "front_urf_link";
124  range_msg.min_range = 0.3;
125  range_msg.max_range = 3.0;
126  range_msg.radiation_type = sensor_msgs::Range::ULTRASOUND;
127  range_msg.range = sensors.ultrasonic.distance_mm / 1000.0;
128  range_msg.field_of_view = 0.7f;
129  ric_ultrasonic_pub_.publish(range_msg);
130 
131  /* publish imu */
132  sensor_msgs::Imu imu_msg;
133 
134  tf::Quaternion orientation_q = tf::createQuaternionFromRPY(sensors.imu.roll_rad,
135  sensors.imu.pitch_rad,
136  sensors.imu.yaw_rad);
137  imu_msg.orientation.x = orientation_q.x();
138  imu_msg.orientation.y = orientation_q.y();
139  imu_msg.orientation.z = orientation_q.z();
140  imu_msg.orientation.w = orientation_q.w();
141  imu_msg.angular_velocity.x = sensors.imu.gyro_x_rad;
142  imu_msg.angular_velocity.y = sensors.imu.gyro_y_rad;
143  imu_msg.angular_velocity.z = sensors.imu.gyro_z_rad;
144  imu_msg.linear_acceleration.x = sensors.imu.accl_x_rad;
145  imu_msg.linear_acceleration.y = sensors.imu.accl_y_rad;
146  imu_msg.linear_acceleration.z = sensors.imu.accl_z_rad;
147  imu_msg.header.stamp = ros::Time::now();
148  ric_imu_pub_.publish(imu_msg);
149 
150  /* publish gps if data is available */
151  if (sensors.gps.satellites > 0)
152  {
153  sensor_msgs::NavSatFix gps_msg;
154  sensor_msgs::NavSatStatus gps_status;
155  gps_status.status = sensor_msgs::NavSatStatus::STATUS_SBAS_FIX;
156  gps_status.status = sensor_msgs::NavSatStatus::SERVICE_GPS;
157 
158  gps_msg.latitude = sensors.gps.lat;
159  gps_msg.longitude = sensors.gps.lon;
160  gps_msg.status = gps_status;
161  gps_msg.header.stamp = ros::Time::now();
162 
163  ric_gps_pub_.publish(gps_msg);
164  }
165 }
166 
168  hardware_interface::EffortJointInterface &effort_interface_)
169 {
170  if (!load_ric_hw_)
171  return;
172 
173  /* joint state registration */
175  &torso_.pos,
176  &torso_.vel,
177  &torso_.effort));
178  joint_state_interface.registerHandle(joint_state_handles_.back());
179 
180  /* joint command registration */
181  pos_handles_.push_back(hardware_interface::JointHandle (joint_state_interface.getHandle(torso_.joint_name),
183  effort_interface_.registerHandle(pos_handles_.back());
184 }
185 
187 {
188  if (!load_ric_hw_)
189  return;
190 
191  if (elapsed >= ros::Duration(RIC_WRITE_INTERVAL))
192  {
194  /* add 1500 offset because torso limits in */
195  /* armadillo2 xacro are b/w -500 - 500, */
196  /* and ric servo get value b/w 1000-2000 */
197  torso_pkg.cmd = torso_.command_effort + SERVO_NEUTRAL;
198  //ROS_WARN("torso_.command_effort: %f, RIC CMD: %d ", torso_.command_effort, torso_pkg.cmd);
199  ric_.writeCmd(torso_pkg, sizeof(torso_pkg), ric_interface::protocol::Type::SERVO);
200  }
201 }
202 
203 void RicboardPub::read(const ros::Duration elapsed)
204 {
205  if (!load_ric_hw_)
206  return;
207 
208  /* update robot state according to ric sensor for controller use */
210  double torso_pos = sensors.laser.distance_mm / 1000.0;
211  double lpf_pos = torso_lpf_.update(torso_pos);
212  //ROS_INFO("real: %f, lpf: %f", torso_pos, lpf_pos);
213  torso_.pos = lpf_pos;//sensors.laser.distance_mm / 1000.0;
214  torso_.vel = (torso_.pos - torso_.prev_pos) / elapsed.sec;
217 }
218 
219 
double prev_pos
Definition: ricboard_pub.h:34
torso_joint torso_
Definition: ricboard_pub.h:54
static tf::Quaternion createQuaternionFromRPY(double roll, double pitch, double yaw)
ros::Publisher espeak_pub_
Definition: ricboard_pub.h:60
ros::NodeHandle * nh_
Definition: ricboard_pub.h:57
#define RIC_WRITE_INTERVAL
Definition: ricboard_pub.h:25
void publish(const boost::shared_ptr< M > &message) const
std::vector< hardware_interface::JointStateHandle > joint_state_handles_
Definition: ricboard_pub.h:63
ric_interface::RicInterface ric_
Definition: ricboard_pub.h:56
void setDeltaTime(float input)
void stop()
#define TORSO_JOINT_PARAM
Definition: ricboard_pub.h:23
#define RIC_PORT_PARAM
Definition: ricboard_pub.h:22
void start()
double command_effort
Definition: ricboard_pub.h:36
#define RIC_DEAD_TIMEOUT
Definition: ricboard_pub.h:26
protocol::ultrasonic ultrasonic
double pos
Definition: ricboard_pub.h:32
void startLoop()
double effort
Definition: ricboard_pub.h:35
void connect(std::string port)
ros::Publisher ric_imu_pub_
Definition: ricboard_pub.h:50
#define ROS_WARN(...)
void pubTimerCB(const ros::TimerEvent &event)
void setCutOffFrequency(float input)
RicboardPub(ros::NodeHandle &nh)
Definition: ricboard_pub.cpp:4
void read(const ros::Duration elapsed)
ROSCPP_DECL bool get(const std::string &key, std::string &s)
#define ROS_INFO(...)
std::string ric_port_
Definition: ricboard_pub.h:47
ROSCPP_DECL bool ok()
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
std::vector< hardware_interface::JointHandle > pos_handles_
Definition: ricboard_pub.h:64
ros::Timer ric_dead_timer_
Definition: ricboard_pub.h:52
protocol::emergency_alarm emrgcy_alarm
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
boost::thread * t
Definition: ricboard_pub.h:58
void write(const ros::Duration elapsed)
void registerHandle(const JointStateHandle &handle)
#define RIC_PUB_INTERVAL
Definition: ricboard_pub.h:24
JointStateHandle getHandle(const std::string &name)
ros::Timer ric_pub_timer_
Definition: ricboard_pub.h:52
#define SERVO_NEUTRAL
Definition: ricboard_pub.h:28
double vel
Definition: ricboard_pub.h:33
float update(float input)
void stopLoop()
static Time now()
ROSCPP_DECL void shutdown()
void writeCmd(const protocol::actuator &actu_pkg, size_t size, protocol::Type type)
ros::Publisher ric_ultrasonic_pub_
Definition: ricboard_pub.h:49
void speakMsg(std::string msg, int sleep_time)
Definition: ricboard_pub.h:69
LowPassFilter torso_lpf_
Definition: ricboard_pub.h:55
bool load_ric_hw_
Definition: ricboard_pub.h:45
int ric_disconnections_counter_
Definition: ricboard_pub.h:46
sensors_state getSensorsState()
std::string joint_name
Definition: ricboard_pub.h:37
#define ROS_ERROR(...)
void ricDeadTimerCB(const ros::TimerEvent &event)
void registerHandles(hardware_interface::JointStateInterface &joint_state_interface, hardware_interface::EffortJointInterface &position_interface)
ros::Publisher ric_gps_pub_
Definition: ricboard_pub.h:48
#define MAX_RIC_DISCONNECTIONS
Definition: ricboard_pub.h:27


armadillo2_hw
Author(s):
autogenerated on Wed Jan 3 2018 03:48:27