第一次的思路完全没有明白相关的定义,一塌糊涂,变量名字被吃了么???Subscriber对应的是subscrible就敢写Publisher 对应的是publish么???
ros::Publisher nh_glob.publish<geometry_msgs::Point>("/position");
ros::Publisher nh_glob.publish<std_msgs::Float64>("/speed");
更正错误error: expected initializer before ‘.’ token ros::Publisher nh_glob.publish
ros::Publisher pubPose = nh_glob.advertise<geometry_msgs::Point>("/position");
ros::Publisher pubSpeed = nh_glob.advertise<std_msgs::Float64>("/speed");
更正错误note: candidate: template ros::Publisher ros::NodeHandle::advertise(const string&, uint32_t, bool)
Publisher advertise(const std::string& topic, uint32_t queue_size, bool latch = false)
写道这里发现写错实验了(,换内容
(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~/ros$ source devel/setup.bash
(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~/ros$ roslaunch dual_planar_arm simulator.launch
... logging to /home/warmtree/.ros/log/c259be4e-8907-11ea-a281-60f677506757/roslaunch-warmtree-HP-Pavilion-Laptop-15-cc5xx-9983.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
started roslaunch server http://warmtree-HP-Pavilion-Laptop-15-cc5xx:38229/
SUMMARY
========
PARAMETERS
* /joint_state_publisher/use_gui: True
* /robot_description: <robot name="dual...
* /rosdistro: melodic
* /rosversion: 1.14.3
NODES
/
joint_state_publisher (joint_state_publisher/joint_state_publisher)
robot (dual_planar_arm/simulator)
robot_state_publisher (robot_state_publisher/robot_state_publisher)
rviz (rviz/rviz)
ROS_MASTER_URI=http://localhost:11311
process[robot_state_publisher-1]: started with pid [9998]
process[joint_state_publisher-2]: started with pid [9999]
process[robot-3]: started with pid [10000]
process[rviz-4]: started with pid [10012]
Traceback (most recent call last):
File "/opt/ros/melodic/lib/joint_state_publisher/joint_state_publisher", line 3, in
import rospy
File " /opt/ros/melodic/lib/python2.7/dist-packages/rospy/__init__.py", line 49, in
from .client import spin, myargv, init_node, \
File " /opt/ros/melodic/lib/python2.7/dist-packages/rospy/client.py", line 52, in
import roslib
File " /opt/ros/melodic/lib/python2.7/dist-packages/roslib/__init__.py", line 50, in
from roslib.launcher import load_manifest
File " /opt/ros/melodic/lib/python2.7/dist-packages/roslib/launcher.py", line 42, in <module>
import rospkg
ModuleNotFoundError: No module named 'rospkg'
[joint_state_publisher-2] process has died [pid 9999, exit code 1, cmd /opt/ros/melodic/lib/joint_state_publisher/joint_state_publisher /joint_states:=/joint_command __name:=joint_state_publisher __log:=/home/warmtree/.ros/log/c259be4e-8907-11ea-a281-60f677506757/joint_state_publisher-2.log].
log file: /home/warmtree/.ros/log/c259be4e-8907-11ea-a281-60f677506757/joint_state_publisher-2*.log
第一个错误很友善,==ModuleNotFoundError: No module named ‘rospkg’==由于用的不是学校虚拟机,所以要自己额外安装rospkg
pip install rospkg //更新方式1
sudo apt-get install python-rospkg //更新方式2
br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "base", "goal"));
This is where the real work is done. Sending a transform with a TransformBroadcaster requires four arguments.
1.First, we pass in the transform itself.
2.Now we need to give the transform being published a timestamp, we’ll just stamp it with the current time, ros::Time::now().
3.Then, we need to pass the name of the parent frame of the link we’re creating, in this case “world”
4.Finally, we need to pass the name of the child frame of the link we’re creating, in this case this is the name of the turtle itself.
Note: sendTransform and StampedTransform have opposite ordering of parent and child.
对应好我们的基础坐标系和目标坐标系,我们就可以通过
rosrun tf tf_echo /base /goal
命令来查看当前的位置信息了。
当我们创建了Tf消息广播之后,我们就可以开始创建TF监听器从而获取我们想要知道的位置信息了。我们已经把左手机械臂的位置信息相对于左前臂的位置信息当作广播发布出去了。现在我们想要得到右手臂到左手臂的坐标变换,进而控制右手臂的移动。
获取监听位置信息使用transform.getOrigin().x(),transform.getOrigin().y()
。
我们现在定义的监听器节点也同时是计算右手臂IGM服务的客户。我们要把业务外包给合适的人来做。
ROS Services 在.srv 文件里面编写(包含应答信息),
ros::ServiceServer service = nh_glob.advertiseService("/right_arm_IK_service", right_arm_IK_service);
创建一个名字是"right_arm_IK_service的服务,注册回调函数right_arm_IK_service。回调函数里包含了所有服务功能。
接下来需要解决客户的问题。
首先使用布尔变量来检查服务是否有问题。
bool ros::ServiceClient::exists ( )
Checks if this is both advertised and available.
Returns: true if the service is up and available, false otherwise
bool ros::ServiceClient::call ( const SerializedMessage & req,
SerializedMessage & resp,
const std::string & service_md5sum
)
Call the service aliased by this handle with the specified service request/response.
看完了参考部分介绍,然而对解决问题并没有什么帮助(
我们的.srv文件名字是DualArmIK.srv.
我们在终端中运行rosservce list
,查看现有的服务有什么
(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~/ros$ rosservice list
/joint_state_publisher/get_loggers
/joint_state_publisher/set_logger_level
/move_left_arm/get_loggers
/move_left_arm/set_logger_level
/robot/get_loggers
/robot/set_logger_level
/robot_state_publisher/get_loggers
/robot_state_publisher/set_logger_level
/rosout/get_loggers
/rosout/set_logger_level
/rviz/get_loggers
/rviz/reload_shaders
/rviz/set_logger_level
/rviz_1588047730142082001/get_loggers
/rviz_1588047730142082001/reload_shaders
/rviz_1588047730142082001/set_logger_level
/tf_br/get_loggers
/tf_br/set_logger_level
/tf_echo_1588060618923278706/get_loggers
/tf_echo_1588060618923278706/set_logger_level
/tracker/get_loggers
/tracker/set_logger_level
我去,什么情况,实验课上到一半,才发现我最开始的选择是对的,明明就该是LAB3,为什么老师要在开始的时候讲解LAB4的内容结果做实验时却是LAB3!!!!!!
世界对我也太“温柔”了吧,今天只好将错就错了(,可恶,可恶,可恶,愚不可及。