|
@@ -15,11 +15,11 @@
|
|
using namespace webots;
|
|
using namespace webots;
|
|
|
|
|
|
Paho_client* client_= nullptr;
|
|
Paho_client* client_= nullptr;
|
|
-TimedLockData<NavMessage::Speed> g_speed;
|
|
|
|
|
|
+TimedLockData<NavMessage::ToAgvCmd> g_speed;
|
|
|
|
|
|
void SpeedChangeCallback(std::string topic,int QOS,MqttMsg& msg,void* context)
|
|
void SpeedChangeCallback(std::string topic,int QOS,MqttMsg& msg,void* context)
|
|
{
|
|
{
|
|
- NavMessage::Speed speed;
|
|
|
|
|
|
+ NavMessage::ToAgvCmd speed;
|
|
msg.toProtoMessage(speed);
|
|
msg.toProtoMessage(speed);
|
|
g_speed.reset(speed,0.3);
|
|
g_speed.reset(speed,0.3);
|
|
}
|
|
}
|
|
@@ -64,36 +64,83 @@ void Rotating(double wmg,double w,double l,
|
|
L4=(velocity);
|
|
L4=(velocity);
|
|
}
|
|
}
|
|
|
|
|
|
-void Horizontal(double velocity,double& R1,double& R2,double& R3,double& R4,
|
|
|
|
- double& L1,double& L2,double& L3,double& L4)
|
|
|
|
-{
|
|
|
|
- R1=-M_PI/2.0;
|
|
|
|
- R2=M_PI/2.0;
|
|
|
|
- R3=M_PI/2.0;
|
|
|
|
- R4=-M_PI/2.0;
|
|
|
|
- L1=-velocity;
|
|
|
|
- L2=velocity;
|
|
|
|
- L3=velocity;
|
|
|
|
- L4=-velocity;
|
|
|
|
|
|
+void Vrtical(double velocity,double wmg,double w,double l,double& R1,double& R2,double& R3,double& R4,
|
|
|
|
+ double& L1,double& L2,double& L3,double& L4) {
|
|
|
|
+ if (fabs(wmg) < 0.0001) {
|
|
|
|
+ R1 = R2 = R3 = R4 = 0;
|
|
|
|
+ L1 = L2 = L3 = L4 = velocity;
|
|
|
|
+ printf("virtical111 R1-R4:%.5f %.5f %.5f %.5f L1-L4:%.5f %.5f %.5f %.5f \n",
|
|
|
|
+ R1,R2,R3,R4,L1,L2,L3,L4);
|
|
|
|
+ } else {//有角速度
|
|
|
|
+ double base = pow(velocity / wmg, 2) - (l * l / 4);
|
|
|
|
+ //满足运动方程
|
|
|
|
+ if (base >= 0.0001) {
|
|
|
|
+ double BaseR = sqrt(base) - w / 2;
|
|
|
|
+
|
|
|
|
+ if (BaseR < 0.05)
|
|
|
|
+ BaseR = 0.05;
|
|
|
|
+ //printf("BaseR : %f \n",BaseR);
|
|
|
|
+ if (BaseR > 0) {
|
|
|
|
+ if (wmg * velocity >= 0) {
|
|
|
|
+ R1 = atan(l / BaseR);
|
|
|
|
+ R2 = atan(l / (BaseR + w));
|
|
|
|
+ L3 = BaseR * wmg;
|
|
|
|
+ L4 = (BaseR + w) * wmg;
|
|
|
|
+ R3 = 0;
|
|
|
|
+ R4 = 0;
|
|
|
|
+ L1 = L3 / cos(R1);
|
|
|
|
+ L2 = L4 / cos(R2);
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ R1 = -atan(l / (BaseR + w));
|
|
|
|
+ R2 = -atan(l / BaseR);
|
|
|
|
+ L3 = -(BaseR + w) * wmg;
|
|
|
|
+ L4 = -BaseR * wmg;
|
|
|
|
+ R3 = 0;
|
|
|
|
+ R4 = 0;
|
|
|
|
+ L1 = L3 / cos(R1);
|
|
|
|
+ L2 = L4 / cos(R2);
|
|
|
|
+ }
|
|
|
|
+ printf("virtical222 R1-R4:%.5f %.5f %.5f %.5f L1-L4:%.5f %.5f %.5f %.5f \n",
|
|
|
|
+ R1,R2,R3,R4,L1,L2,L3,L4);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
-void Vrtical(double velocity,double& R1,double& R2,double& R3,double& R4,
|
|
|
|
|
|
+void Horizontal(double velocity,double wmg,double w,double l,double& R1,double& R2,double& R3,double& R4,
|
|
double& L1,double& L2,double& L3,double& L4)
|
|
double& L1,double& L2,double& L3,double& L4)
|
|
{
|
|
{
|
|
- R1=0;
|
|
|
|
- R2=0;
|
|
|
|
- R3=0;
|
|
|
|
- R4=0;
|
|
|
|
- L1=velocity;
|
|
|
|
- L2=velocity;
|
|
|
|
- L3=velocity;
|
|
|
|
- L4=velocity;
|
|
|
|
|
|
+ Vrtical(velocity,wmg,w,l,R3,R1,R4,R2,L3,L1,L4,L2);
|
|
|
|
+
|
|
|
|
+ if (fabs(wmg) < 0.0001) {
|
|
|
|
+ R1 = -M_PI / 2.0;
|
|
|
|
+ R2 = M_PI / 2.0;
|
|
|
|
+ R3 = M_PI / 2.0;
|
|
|
|
+ R4 = -M_PI / 2.0;
|
|
|
|
+ L1 = -velocity;
|
|
|
|
+ L2 = velocity;
|
|
|
|
+ L3 = velocity;
|
|
|
|
+ L4 = -velocity;
|
|
|
|
+ }else{
|
|
|
|
+ R1-=M_PI/2.0;
|
|
|
|
+ R2+=M_PI/2.0;
|
|
|
|
+ R3+=M_PI/2.0;
|
|
|
|
+ R4-=M_PI/2.0;
|
|
|
|
+ L1=-L1;
|
|
|
|
+ L4=-L4;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
int main(int argc, char **argv) {
|
|
int main(int argc, char **argv) {
|
|
//init mqtt
|
|
//init mqtt
|
|
- if(false==init_mqtt("127.0.0.1",1883,"webots","monitor/speedcmd"))
|
|
|
|
|
|
+ if(false==init_mqtt("127.0.0.1",1883,"webots_main","MainPLC/speedcmd"))
|
|
{
|
|
{
|
|
printf(" Init mqtt failed...\n");
|
|
printf(" Init mqtt failed...\n");
|
|
return -1;
|
|
return -1;
|
|
@@ -164,13 +211,13 @@ int main(int argc, char **argv) {
|
|
|
|
|
|
////发布:
|
|
////发布:
|
|
//增加高斯分布
|
|
//增加高斯分布
|
|
- double x=gps->getValues()[2]+ generae_random(generator,0,0.007);
|
|
|
|
- double y=gps->getValues()[0] + generae_random(generator,0,0.007);
|
|
|
|
|
|
+ double x=gps->getValues()[2]+ generae_random(generator,0,0.005);
|
|
|
|
+ double y=gps->getValues()[0] + generae_random(generator,0,0.005);
|
|
double theta=imu->getRollPitchYaw()[2]+generae_random(generator,0,0.1*M_PI/180.0);
|
|
double theta=imu->getRollPitchYaw()[2]+generae_random(generator,0,0.1*M_PI/180.0);
|
|
|
|
|
|
//获取gps速度,判断朝向
|
|
//获取gps速度,判断朝向
|
|
double vm1=R3_l->getVelocity()*radius;
|
|
double vm1=R3_l->getVelocity()*radius;
|
|
- double vm2=-R4_l->getVelocity()*radius;
|
|
|
|
|
|
+ double vm2=-R2_l->getVelocity()*radius;
|
|
double v=gps->getSpeed();
|
|
double v=gps->getSpeed();
|
|
if(vm1+vm2<0.0)
|
|
if(vm1+vm2<0.0)
|
|
v=-v;
|
|
v=-v;
|
|
@@ -189,20 +236,22 @@ int main(int argc, char **argv) {
|
|
if(client_)
|
|
if(client_)
|
|
{
|
|
{
|
|
MqttMsg msg;
|
|
MqttMsg msg;
|
|
- NavMessage::AGVStatu statu;
|
|
|
|
- statu.set_x(x);
|
|
|
|
- statu.set_y(y);
|
|
|
|
- statu.set_theta(theta);
|
|
|
|
- statu.set_v(v);
|
|
|
|
- statu.set_vth(vth);
|
|
|
|
- msg.fromProtoMessage(statu);
|
|
|
|
- client_->publish("monitor/statu",1,msg);
|
|
|
|
-
|
|
|
|
- NavMessage::AGVSpeed speed;
|
|
|
|
|
|
+ NavMessage::LidarOdomStatu odom;
|
|
|
|
+ odom.set_x(x);
|
|
|
|
+ odom.set_y(y);
|
|
|
|
+ odom.set_theta(theta);
|
|
|
|
+ odom.set_v(v);
|
|
|
|
+ odom.set_vth(vth);
|
|
|
|
+ msg.fromProtoMessage(odom);
|
|
|
|
+ client_->publish("lidar_odom/main",1,msg);
|
|
|
|
+
|
|
|
|
+ NavMessage::AgvStatu speed;
|
|
speed.set_v(v);
|
|
speed.set_v(v);
|
|
speed.set_w(vth);
|
|
speed.set_w(vth);
|
|
|
|
+ speed.set_clamp(0);
|
|
|
|
+ speed.set_clamp_other(0);
|
|
msg.fromProtoMessage(speed);
|
|
msg.fromProtoMessage(speed);
|
|
- client_->publish("monitor/speed",1,msg);
|
|
|
|
|
|
+ client_->publish("MainPLC/speed",1,msg);
|
|
}
|
|
}
|
|
|
|
|
|
if(g_speed.timeout())
|
|
if(g_speed.timeout())
|
|
@@ -232,74 +281,29 @@ int main(int argc, char **argv) {
|
|
|
|
|
|
if(g_speed.Get().t()==1) //原地旋转
|
|
if(g_speed.Get().t()==1) //原地旋转
|
|
{
|
|
{
|
|
|
|
+ printf("旋转:");
|
|
if (fabs(cmd_vth) > 0.0001)
|
|
if (fabs(cmd_vth) > 0.0001)
|
|
Rotating(cmd_vth, w / 2.0, l / 2.0, R1, R2, R3, R4, L1, L2, L3, L4);
|
|
Rotating(cmd_vth, w / 2.0, l / 2.0, R1, R2, R3, R4, L1, L2, L3, L4);
|
|
}
|
|
}
|
|
else if(g_speed.Get().t()==2) //横移
|
|
else if(g_speed.Get().t()==2) //横移
|
|
{
|
|
{
|
|
- Horizontal(g_speed.Get().v(),R1, R2, R3, R4, L1, L2, L3, L4);
|
|
|
|
|
|
+ printf("横移:");
|
|
|
|
+ if (fabs(cmd_vth) > 0.4) {
|
|
|
|
+ cmd_vth = cmd_vth > 0 ? 0.4 : -0.4;
|
|
|
|
+ }
|
|
|
|
+ Horizontal(cmd_v,cmd_vth,l,w,R1, R2, R3, R4, L1, L2, L3, L4);
|
|
}
|
|
}
|
|
- else { //巡线/前进
|
|
|
|
-
|
|
|
|
|
|
+ else if(g_speed.Get().t()==3){ //巡线/前进
|
|
|
|
+ printf("前进:");
|
|
if (fabs(cmd_vth) > 0.4) {
|
|
if (fabs(cmd_vth) > 0.4) {
|
|
cmd_vth = cmd_vth > 0 ? 0.4 : -0.4;
|
|
cmd_vth = cmd_vth > 0 ? 0.4 : -0.4;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- //------------------------------------------------
|
|
|
|
- //无角速度,直线
|
|
|
|
- if (fabs(cmd_vth) < 0.0001) {
|
|
|
|
- R1 = R2 = R3 = R4 = 0;
|
|
|
|
- L1 = L2 = L3 = L4 = cmd_v;
|
|
|
|
- } else //有角速度
|
|
|
|
- {
|
|
|
|
- if (fabs(cmd_v) < 0.00001) {
|
|
|
|
- //原地旋转
|
|
|
|
- if (fabs(cmd_vth) > 0.0001)
|
|
|
|
- Rotating(cmd_vth, w / 2.0, l / 2.0, R1, R2, R3, R4, L1, L2, L3, L4);
|
|
|
|
- } else {
|
|
|
|
- //默认原地旋转
|
|
|
|
- Rotating(cmd_vth, w / 2.0, l / 2.0, R1, R2, R3, R4, L1, L2, L3, L4);
|
|
|
|
- double base = pow(cmd_v / cmd_vth, 2) - (l * l / 4);
|
|
|
|
- //满足运动方程
|
|
|
|
- if (base >= 0.0001) {
|
|
|
|
- double BaseR = sqrt(base) - w / 2;
|
|
|
|
-
|
|
|
|
- if(BaseR<0.05)
|
|
|
|
- BaseR=0.05;
|
|
|
|
- //printf("BaseR : %f \n",BaseR);
|
|
|
|
-
|
|
|
|
- if (BaseR > 0) {
|
|
|
|
- if (cmd_vth * cmd_v >= 0) {
|
|
|
|
- R1 = atan(l / BaseR);
|
|
|
|
- R2 = atan(l / (BaseR + w));
|
|
|
|
- L3 = BaseR * cmd_vth;
|
|
|
|
- L4 = (BaseR + w) * cmd_vth;
|
|
|
|
- R3 = 0;
|
|
|
|
- R4 = 0;
|
|
|
|
- L1 = L3 / cos(R1);
|
|
|
|
- L2 = L4 / cos(R2);
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- R1 = -atan(l / (BaseR + w));
|
|
|
|
- R2 = -atan(l / BaseR);
|
|
|
|
- L3 = -(BaseR + w) * cmd_vth;
|
|
|
|
- L4 = -BaseR * cmd_vth;
|
|
|
|
- R3 = 0;
|
|
|
|
- R4 = 0;
|
|
|
|
- L1 = L3 / cos(R1);
|
|
|
|
- L2 = L4 / cos(R2);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ Vrtical(cmd_v,cmd_vth,w,l,R1,R2,R3,R4,L1,L2,L3,L4);
|
|
}
|
|
}
|
|
|
|
|
|
printf("Child R1-R4:%.5f %.5f %.5f %.5f L1-L4:%.5f %.5f %.5f %.5f V:%.5f Vth:%.5f\n",
|
|
printf("Child R1-R4:%.5f %.5f %.5f %.5f L1-L4:%.5f %.5f %.5f %.5f V:%.5f Vth:%.5f\n",
|
|
- R1,R2,R3,R4,L1,L2,L3,L4,v,vth);
|
|
|
|
|
|
+ R1,R2,R3,R4,L1,L2,L3,L4,cmd_v,cmd_vth);
|
|
|
|
|
|
RM1->setPosition(R1);
|
|
RM1->setPosition(R1);
|
|
RM2->setPosition(R2);
|
|
RM2->setPosition(R2);
|