Skip to content
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
2 changes: 1 addition & 1 deletion tfmini_ros/include/TFmini.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace benewake
std::string portName_;
int baudRate_;
int serial_;

int available_bytes();
bool readData(unsigned char *_buf, int _nRead);
};
}
12 changes: 10 additions & 2 deletions tfmini_ros/src/TFmini.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <TFmini.h>
#include <ros/ros.h>

#include <sys/ioctl.h>
//#define DEBUG

namespace benewake
Expand Down Expand Up @@ -85,7 +85,9 @@ namespace benewake
bool TFmini::readData(unsigned char* _buf, int _nRead)
{
int total = 0, ret = 0;

while (available_bytes() < _nRead) {
usleep(100);
}
while(total != _nRead)
{
ret = read(serial_, _buf + total, (_nRead - total));
Expand All @@ -106,6 +108,12 @@ namespace benewake
return true;
}

int TFmini::available_bytes() {
int ret = 0;
ioctl(serial_, FIONREAD, &ret);
return ret;
}

float TFmini::getDist()
{
while(true)
Expand Down
7 changes: 5 additions & 2 deletions tfmini_ros/src/TFmini_ros_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ int main(int argc, char **argv)
int baud_rate;
benewake::TFmini *tfmini_obj;

ros::Rate r(60);

nh.param("serial_port", portName, std::string("/dev/ttyUSB0"));
nh.param("baud_rate", baud_rate, 115200);

Expand All @@ -23,9 +25,9 @@ int main(int argc, char **argv)
float dist = 0;
ROS_INFO_STREAM("Start processing ...");

while(ros::master::check() && ros::ok())
while( ros::ok())
{
ros::spinOnce();
// ros::spinOnce();
dist = tfmini_obj->getDist();
if(dist > 0 && dist < TFmini_range.max_range)
{
Expand All @@ -42,6 +44,7 @@ int main(int argc, char **argv)
{
ROS_ERROR_STREAM("Data validation error!");
}
// r.sleep();
}

tfmini_obj->closePort();
Expand Down