玩家/舞台-机器人在模拟中没有移动?
我是玩家/舞台的新手。但不知怎的,我设法想出了下面的代码,但没有移动
首先配置文件
driver
(
name "stage"
provides ["simulation:0"]
plugin "stageplugin"
#load the world file
worldfile "robotWorld.world"
)
driver
(
name "stage"
provides [
"position2d:0"
"laser:0"
]
model "robot"
)
map.inc文件
define map model
(
#color of the map
color "black"
#we need a boundary wall aroung the map, then only the robot can't go outside of the map
boundary 1
gui_nose 1
gui_grid 1
gui_movemask 0
gui_outline 0
fiducial_reurn 0
gripper_return 0
)
robot.inc文件
define robots_laser laser
(
# minimum range of the laser
range_min 0.0
#maximum range of the laser
range_max 2
#field of view or pan angle of the camera
#fov 180
#assume the robot's size as 400*200, and the camera is in the front end
pose [200 100 0 0]
#size of the camera
size [0.025 0.025 0.001]
)
define robot position
(
#size of the robot
size [50 50 50]
#as a default centre of rotation is the geometry centre
#shape of the robot
polygons 1
polygon[0].points 4
polygon[0].point[0] [0 0]
polygon[0].point[1] [1 0]
polygon[0].point[2] [1 1]
polygon[0].point[3] [0 1]
# car steering model
drive "car"
#mass of the robot
mass 10.0
robots_laser()
)
世界文件是
include "robot.inc"
include "map.inc"
#size of the simulation
size [15 15]
#interval_sim=5
#interval_real=10
#GUI window
window
(
size [700 700]
scale 2.5
show_data 1
)
map
(
bitmap "map2"
size [300 300 3]
)
robot
(
name "robot"
pose [0 0 0 0]
color "Green"
)
这是主cpp文件(mainCode.cpp)
#include<iostream>
#include<unistd.h>
#include<time.h>
#include<player-3.0/libplayerc++/playerc++.h>
using namespace std;
int main(int argc,char * argv[])
{
using namespace PlayerCc;
cout << "111111111111" << endl ;
PlayerClient robotClient("localhost",6665);
Position2dProxy p2dProxy(&robotClient,0);
LaserProxy laserProxy(&robotClient,0);
p2dProxy.SetMotorEnable(true);
p2dProxy.RequestGeom();
robotClient.Read();
while(true)
{
robotClient.Read();
p2dProxy.SetCarlike(240,0);
cout << laserProxy[45] << endl ;
}
cout << "reached the end of the coding" << endl ;
}
一切都很好,但是机器人没有移动,所以在上面的代码中我得到一个恒定值作为输出。而在模拟中机器人是不动的。有人请帮帮我吗?
I am new to player/stage. But somehow I managed to come up with the below code but is not moving
First the configuration file
driver
(
name "stage"
provides ["simulation:0"]
plugin "stageplugin"
#load the world file
worldfile "robotWorld.world"
)
driver
(
name "stage"
provides [
"position2d:0"
"laser:0"
]
model "robot"
)
The map.inc file
define map model
(
#color of the map
color "black"
#we need a boundary wall aroung the map, then only the robot can't go outside of the map
boundary 1
gui_nose 1
gui_grid 1
gui_movemask 0
gui_outline 0
fiducial_reurn 0
gripper_return 0
)
The robot.inc file
define robots_laser laser
(
# minimum range of the laser
range_min 0.0
#maximum range of the laser
range_max 2
#field of view or pan angle of the camera
#fov 180
#assume the robot's size as 400*200, and the camera is in the front end
pose [200 100 0 0]
#size of the camera
size [0.025 0.025 0.001]
)
define robot position
(
#size of the robot
size [50 50 50]
#as a default centre of rotation is the geometry centre
#shape of the robot
polygons 1
polygon[0].points 4
polygon[0].point[0] [0 0]
polygon[0].point[1] [1 0]
polygon[0].point[2] [1 1]
polygon[0].point[3] [0 1]
# car steering model
drive "car"
#mass of the robot
mass 10.0
robots_laser()
)
The world file is
include "robot.inc"
include "map.inc"
#size of the simulation
size [15 15]
#interval_sim=5
#interval_real=10
#GUI window
window
(
size [700 700]
scale 2.5
show_data 1
)
map
(
bitmap "map2"
size [300 300 3]
)
robot
(
name "robot"
pose [0 0 0 0]
color "Green"
)
This is the main cpp file (mainCode.cpp)
#include<iostream>
#include<unistd.h>
#include<time.h>
#include<player-3.0/libplayerc++/playerc++.h>
using namespace std;
int main(int argc,char * argv[])
{
using namespace PlayerCc;
cout << "111111111111" << endl ;
PlayerClient robotClient("localhost",6665);
Position2dProxy p2dProxy(&robotClient,0);
LaserProxy laserProxy(&robotClient,0);
p2dProxy.SetMotorEnable(true);
p2dProxy.RequestGeom();
robotClient.Read();
while(true)
{
robotClient.Read();
p2dProxy.SetCarlike(240,0);
cout << laserProxy[45] << endl ;
}
cout << "reached the end of the coding" << endl ;
}
Every thing is fine but the robot is not moving, So In the above code I am getting a constant value as the output. And in the simulation robot is not moving. Anybody, please help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在控制器外部,播放器/舞台是线程化的。但是,您的代码必须管理它自己的资源。因此,您需要放弃执行时间,以便其他事物(例如您订阅的代理)可以运行。
在 while 循环末尾添加 sleep 调用。这将允许代理更新数据(往返于玩家/舞台),以便您收到新的传感器数据并且玩家获得新的速度命令。
External to your controller, Player/Stage is threaded. However, your code must manage it's own resources. So, you need to give up execution time so that other things (like the proxies you've subscribed to) can run.
Add a sleep call at the end of your while loop. This will allows the proxies to update data (both to and from player/stage) so you receive new sensor data and player gets new velocity commands.