User Tools

Site Tools


neurali:ros_husky_laser_versione_20150801

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

neurali:ros_husky_laser_versione_20150801 [2020/06/08 22:20] (current)
Line 1: Line 1:
 +visualizza le distante ottenute dal laser in 8 direzioni (cercare la costante numerica 8)
  
 +<code cpp>
 +
 +#include <ros/ros.h>
 +#include <geometry_msgs/Twist.h>
 +#include <sensor_msgs/LaserScan.h>
 +#include <iostream>
 +
 +class DriverHusky
 +{
 +public:
 +  DriverHusky();
 + 
 +private:
 +  void laserCallback(const sensor_msgs::LaserScan::ConstPtr& laser);
 + 
 +  ros::NodeHandle nh_;
 + 
 +  ros::Publisher vel_pub_;
 +  ros::Subscriber laser_sub_;
 + 
 +};
 + 
 + 
 +DriverHusky::DriverHusky()
 +{
 + 
 +  //vel_pub_ = nh_.advertise<geometry_msgs::Twist>("cmd_vel", 1);
 + 
 +  laser_sub_ = nh_.subscribe<sensor_msgs::LaserScan>("/scan", 10, &DriverHusky::laserCallback, this);
 + 
 +}
 +
 +void DriverHusky::laserCallback(const sensor_msgs::LaserScan::ConstPtr& laser)
 +
 +/*  //riceve e trasforma da joy a vel
 +  geometry_msgs::Twist vel;
 +  vel.angular = a_scale_*joy->axes[angular_];
 +  vel.linear = l_scale_*joy->axes[linear_];
 +  vel_pub_.publish(vel);*/ 
 +  
 +  unsigned int quantita = laser->ranges.size();
 +  for(unsigned int i=0; i< quantita; i=i+quantita/8)
 +  {
 +       
 +       std::cout << laser->ranges[i] << "," ;
 +  }
 +
 +    std::cout << std::endl;  
 +}
 +
 +int main(int argc, char** argv)
 +
 +
 +  ros::init(argc, argv, "husky_driver");
 +  DriverHusky driver_hurky;
 +  ros::Rate rate(10);  //aggiunto 
 +  ros::spin();
 +}
 +</code>
neurali/ros_husky_laser_versione_20150801.txt ยท Last modified: 2020/06/08 22:20 (external edit)