I have a class that has a member variable which is an object of another class
class SuperScanner {
public:
SuperScanner(ros::NodeHandle& nh, std::string cameraIP);
// Other functions
private:
Motor _motor;
Camera _camera;
// Other variables and functions
.....
}
Within a function in the SuperScanner class, I'm creating a new thread that invokes image acquisition and then starts the motor motion. The camera needs to start recording before the motion starts, but must continue for a certain duration of time while the motor still moves.To do this, I'm using boost threads.
SuperScanner::getData() {
boost::function<void()> scanFunc = boost::bind(&Camera::startAcquiring, _camera, scanTime,
boost::ref(cameraStatus), boost::ref(_results));
// Start acquiring
std::shared_ptr<boost::thread> threadPtr = std::make_shared<boost::thread>(scanFunc);
// Send motor to target position
_motor.send();
// Join thread
threadPtr->join();
_log.print("Finished the acquisition");
}
This seems to run into trouble sometimes, with the ros spin thread getting blocked and not executing any callbacks to other topics subscribed to in SuperScanner. The "Finished the acquisition" statement does get printed out though, so I know the thread has joined. A ronsode info on the node shows the list of topics, but says "communication with node failed". Could this have anything to do with the member variables within the instance of the _camera object getting updated in its startAcquiring() function?
Here's how the node gets started:
int main(int argc, char** argv)
{
ros::init(argc, argv, "super_scanner");
ros::NodeHandle n("~");
n.param("/camera_scanner/device_ip", deviceIP, deviceIP);
SuperScanner superScanner(n, deviceIp);
ros::spin();
return 0;
}
Originally posted by space on ROS Answers with karma: 13 on 2020-06-17
Post score: 0
Original comments
Comment by Solrac3589 on 2020-06-18:
Maybe this comment is a little offtopic, but i personally feel like you could have better control of the system if you used a separate nodelet for image adquisition.