程序正在调试中,争取能够实现转弯性能的同时,实现实现更快速度,以前用单片机做,速度不能快,速度一块转弯就会跟不上,就会偏离黑色轨道,无法循迹。当然之前我用的是普通控制,没有用瑞萨单片机PID之类那么复杂的控制
视频地址:http://player.youku.com/player.php/sid/XNTQ2MDk3NTI0/v.swf
show一下我的车
2013/0416追加,还是老问题,跟用mcu控制差不多,速度一快转向不灵活,还是要从机械结构上解决转向问题,电机的pwm控制,周期太短的话电机啸叫,不会启动。
module car(
sys_clk,
in1,
in2,
in3,
in4,
ena,
enb,
detect_a,
detect_b);
input sys_clk;
output in1;
reg in1;
output in2;
reg in2;
output in3;
reg in3;
output in4;
reg in4;
output ena;
reg ena;
output enb;
reg enb;
input detect_a;
input detect_b;
reg [9:0] go_state;
reg [9:0] left_state;
reg [9:0] right_state;
reg [9:0] wrong_state;
reg [30:0] go_clk;
reg [30:0] stop_clk;
reg [30:0] left_clk;
reg [30:0] right_clk;
parameter state_0=0;
parameter state_1=1;
parameter state_2=2;
parameter state_3=3;
parameter state_4=4;
parameter state_5=5;
parameter state_6=6;
parameter state_7=7;
/*各个引脚定义
pin161---->in1
pin163---->in2
pin165---->in3
pin169---->in4
pin191---->ena
pin195---->enb
pin193---->detect_a
pin205---->detect_b
*/
always@(posedge sys_clk)
begin
if((detect_a==1'b1)&&(detect_b==1'b1))
begin
case(go_state)
state_0:
begin
right_clk<=0;
right_state<=0;
left_clk<=0;
left_state<=0;
go_clk<=0;
stop_clk<=0;
go_state<=state_1;
end
state_1:
begin
if(go_clk>=31'd1500000)
begin
go_clk<=0;
go_state<=state_2;
end
else
begin
ena=1'b1;
enb=1'b1;
in1=0;
in2=1'b1;
in3=0;
in4=1'b1;
go_clk<=go_clk+1'b1;
go_state<=state_1;
end
end
state_2:
begin
if(stop_clk>=31'd10000)
begin
stop_clk<=0;
go_state<=state_0;
end
else
begin
ena=0;
enb=0;
in1=0;
in2=1'b1;
in3=0;
in4=1'b1;
stop_clk<=stop_clk+1'b1;
go_state<=state_2;
end
end
endcase
end
else if((detect_a==0)&&(detect_b==1'b1))
begin
case(left_state)
state_0:
begin
right_clk<=0;
right_state<=0;
go_state<=0;
go_clk<=0;
stop_clk<=0;
left_state<=state_1;
end
state_1://左边轮子探到黑线
begin
if(left_clk>=31'd180000000)
begin
left_clk<=0;
left_state<=state_2;
end
else
begin
ena=1'b1;
enb=1'b1;
in1=1'b1;
in2=0;//反转
in3=0;
in4=1'b1;//正转
left_clk<=left_clk+1'b1;
left_state<=state_1;
end
end
state_2:
begin
left_state<=state_0;
end
endcase
end
else if((detect_a==1'b1)&&(detect_b==0))//右边轮子探到黑线
begin
case(right_state)
state_0:
begin
right_clk<=0;
left_state<=0;
left_clk<=0;
go_state<=0;
go_clk<=0;
stop_clk<=0;
right_state<=state_1;
end
state_1:
begin
if(right_clk>=31'd180000000)
begin
right_clk<=0;
right_state<=state_2;
end
else
begin
ena=1'b1;
enb=1'b1;
in1=0;
in2=1'b1;//正转
in3=1'b1;
in4=0;//反转
right_clk<=right_clk+1'b1;
right_state<=state_1;
end
end
state_2:
begin
right_state<=state_0;
end
endcase
end
else if((detect_a==0)&&(detect_b==0))
begin
case(wrong_state)
state_0:
begin
right_clk<=0;
right_state<=0;
left_state<=0;
left_clk<=0;
go_state<=0;
go_clk<=0;
stop_clk<=0;
wrong_state<=state_1;
end
state_1:
begin
/* ena=0;
enb=0;
in1=0;
in2=1'b1;
in3=0;
in4=1'b1;*/
wrong_state<=state_0;
end
endcase
end
end
endmodule