I want to take the distance value and degree value from the client node and control it with Python.
I want to control it by python by receiving the distance value and degree value from the client. However, no value appears when the node is operated.Help me, please.
include "ros/ros.h"
include "sensor_msgs/LaserScan.h"
include "rplidar.h"
include <vector>
include "hal/types.h"
include "rplidar_protocol.h"
include "rplidar_cmd.h"
include "rplidar_driver.h"
class SubscribeAndPublish {
public: SubscribeAndPublish() { //#퍼블리쉬 할 토픽 선언 pub_ = n_.advertise<sensor_msgs::laserscan>("/scan_1",1);
//#서브스크라이 할 토픽 선언
sub_ = n_.subscribe("/scan",1, &SubscribeAndPublish::scanCallback, this);
}
define RAD2DEG(x) ((x)*180./M_PI)
void scanCallback(const sensor_msgs::LaserScan::ConstPtr& scan)
{
sensor_msgs::LaserScan output;
int count = scan->scan_time / scan->time_increment;
for(int i = 0; i < count; i++) {
float degree = RAD2DEG(scan->angle_min + scan->angle_increment * i);
ROS_INFO(": [%f, %f]", degree, scan->ranges[i]);
}
pub_.publish(output);
}
private: ros::NodeHandle n_; ros::Publisher pub_; ros::Subscriber sub_; };
int main(int argc, char **argv) { ros::init(argc, argv, "rplidar_ros_Client");
SubscribeAndPublish SAPObject;
ros::spin();
return 0;
}
Code subscribed by client node.I want to control the distance value and degree value from this code to Python. It's the code I wrote.
! /usr/bin/env python
import rospy from sensor_msgs.msg import LaserScan import rplidar import vector import time from math import pi import numpy as np def rad2deg(x): return x*180/pi
def callback(msg):
angle_min = msg.angle_min
angle_max = msg.angle_max
angle_icrement = msg.angle_increment
time_increment = msg.time_increment
time_increment_plus = time_increment + np.exp(-60)
float(time_increment_plus)
scan_time = msg.scan_time
range_min = msg.range_min
range_max = msg.range_max
ranges = msg.ranges
count = scan_time/ time_increment_plus
count = int(count)
degree_list=[]
for i in range (count):
if i < count:
for a in range (10000):
degree = rad2deg(angle_min + angle_icrement)
degree_list.append(degree)
print("degree : %f, distance : %f"%(degree_list[i] , ranges[i]))
def main(): rospy.init_node('distance_angle') rospy.Subscriber("/scan_1",LaserScan,callback) rospy.spin() return 0
if __name__ == '__main__': main()