转弯的话 高速可以正转一边反转 低速一边正转 另一边锁死 或者转一个我比较笨 到现在都没学会pwm 所以只有这本办法了~
inline void rob_control(std::vector<cv::Point>&_contour){ros::Rate loopRate(10)
int rcount=0
int lcount=0
int r_state = 0
int l_state = 0
int in_cl = 8//运动状态改变的阈值
for(unsigned i=0i<_contour.size()i++)
{
cv::Point p=_contour[i]
PointT pointx=down_cloud->at(p.x*downScale,p.y*downScale)
//todo 安全距离和宽度设定
if(pointx.x<0.3&&pointx.x>-0.25&&pointx.z<1.2)
{
if(pointx.x>0)
{
rcount++
}
else if(pointx.x<0)
{
lcount++
}
pre_imageViewer->addCircle( p.x*downScale,p.y*downScale, 3, 1, 0.2,0.1, "contour", 1)
continue
}
pre_imageViewer->addCircle( p.x*downScale,p.y*downScale, 1, 0, 1,1, "contour", 1)
}
while (ros::ok()){
if(lcount>in_cl&&rcount==0)
{
//turn right
if(l_state == 0)
{
tr()
r_state = 1
l_state = 0
std::cout<<"当前路面进行右转。"<<endl
}
else
{
tl()
l_state = 1
r_state = 0
std::cout<<"当前路面进行左转。"<<endl
}
}
else if(lcount==0&&rcount>in_cl)
{
//turn left
if(r_state == 0)
{
tl()
r_state = 0
l_state = 1
}
else
{
tr()
r_state = 1
l_state = 0
}
}
else if(lcount>in_cl&&rcount>in_cl)
{
//stop
std::cout<<"复杂情况 : 多个障碍物"<<endl
st()
tr()
r_state = 1
l_state = 0
}
else
{
gs()
l_state= 0
r_state = 0
}
}
}
首先设定一个黑白的阈值,如果左黑,中黑,右白,则右转;
如果左黑,中白,右黑,则直行;
如果左白,中黑,右黑,则左转。
(如果左黑,中黑,右黑,则停止)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)