Macros | Functions | Variables
camera_webots.cpp File Reference
#include <std_msgs/String.h>
#include "ros/ros.h"
#include <signal.h>
#include <image_transport/image_transport.h>
#include "rosinljubljana/rosinljubljana.h"
Include dependency graph for camera_webots.cpp:

Go to the source code of this file.

Macros

#define TIME_STEP   32
 

Functions

void controllerNameCallback (const std_msgs::String::ConstPtr &name)
 
int main (int argc, char **argv)
 
void quit (int sig)
 

Variables

static int controllerCount
 
static std::vector< std::string > controllerList
 

Detailed Description

Example of rosinljubljana package for constructing a camera for webots simulation environment:

/*! \file camera_webots.cpp
 *  Example of rosinljubljana package for constructing a camera for webots simulation environment:
 *  \verbinclude camera_webots.cpp
 */

#include <std_msgs/String.h>
#include "ros/ros.h"
#include <signal.h>

#include <image_transport/image_transport.h>

#include "rosinljubljana/rosinljubljana.h"

#define TIME_STEP 32

static int controllerCount;
static std::vector<std::string> controllerList;

// catch names of the controllers availables on ROS network
void controllerNameCallback(const std_msgs::String::ConstPtr &name) {
  controllerCount++;
  controllerList.push_back(name->data);
  ROS_INFO("Controller #%d: %s.", controllerCount, controllerList.back().c_str());
}

void quit(int sig) {
  ROS_INFO("User stopped the 'robot_information_parser' node.");
  ros::shutdown();
  exit(0);
}

int main(int argc, char **argv) {

  std::string controllerName;
  std::vector<std::string> deviceList;
  int width, height;

  // create a node named 'robot_information_parser' on ROS network
  ros::init(argc, argv, "camera", ros::init_options::AnonymousName);
  ros::NodeHandle n;

  image_transport::ImageTransport it(n);
  signal(SIGINT, quit);

  // subscribe to the topic model_name to get the list of availables controllers
  ros::Subscriber nameSub = n.subscribe("model_name", 100, controllerNameCallback);
  while (controllerCount < 3 || controllerCount < nameSub.getNumPublishers()) {
    ros::spinOnce();
    ros::spinOnce();
    ros::spinOnce();
  }
  ros::spinOnce();

  for (int i = 0; i<controllerCount; i++){
    if (controllerList[i].find("CAMERA") != std::string::npos) {
      controllerName = controllerList[i];
    }

  }

  // leave topic once it is not necessary anymore
  nameSub.shutdown();

  // create camera object
  WebotsCamera kamera(n, it, controllerName);
  kamera.enable(n);
  kamera.setFrames();
  kamera.subscribe(n);
  kamera.setCamInfo();
  //tf::Quaternion q_rot;
  //q_rot.setRPY(0.0, -1.56, 0.0);
  //kamera.setPositionOrientation(tf::Vector3(0.0, 0.0, 1.5), q_rot);

  while(ros::ok()){
    // publish camera image
    kamera.publish();
    kamera.transmitFrames();
    ros::spinOnce();
  }
}

Definition in file camera_webots.cpp.

Macro Definition Documentation

◆ TIME_STEP

#define TIME_STEP   32

Definition at line 14 of file camera_webots.cpp.

Function Documentation

◆ controllerNameCallback()

void controllerNameCallback ( const std_msgs::String::ConstPtr &  name)

Definition at line 20 of file camera_webots.cpp.

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 32 of file camera_webots.cpp.

◆ quit()

void quit ( int  sig)

Definition at line 26 of file camera_webots.cpp.

Variable Documentation

◆ controllerCount

int controllerCount
static

Definition at line 16 of file camera_webots.cpp.

◆ controllerList

std::vector<std::string> controllerList
static

Definition at line 17 of file camera_webots.cpp.



rosinljubljana
Author(s): Igor Banfi
autogenerated on Mon Feb 24 2020 12:32:36