本帖最后由 swanglei 于 2018-3-28 11:24 编辑
这次比赛相对于其他小伙伴来说,我们花费的时间和精力比较少,一方面没什么经验,另外一方面没那么多时间搞机,所以比赛结果也在预料之中,一轮游,哈哈 MechBattle首轮比赛视频 由于这个机器人我主要负责电路和程序,结构和外形是茅教授设计的,所以呢,这篇文章我就总结一些电路和程序上的心得。 还是先来看看茅教授的设计过程:
原本的计划是用3D打印制作机身
实际在测试过程中发现3D打印的机身承受不住撞击,所以后面我们用铝合金制作了一套,但是从比赛结果来看,还是承受不住撞击。
好了,接下来我主要来说一下电路和程序上的细节。 DF给参赛者提供了一对减速电机外加一块PMM信号控制的电机驱动板,由于手头上没有好的遥控,所以放弃使用了这块电机驱动板,在淘宝上淘到PWM的电机驱动板: 可以在5A内稳定工作,基本上还是符合要求的。接下来是武器的电机:895有刷直流电机
这个电机足足一斤重,驱动方式是使用继电器作为开关(895电机启动电流要10A左右,而手上这块DF的继电器刚好最大电流是10A,所以就不去看其他的了)
至于电池的选择,我选择了一个12V,30C,2000mah的3S锂电池 遥控模式我选择了PS2的无线遥控,自己用NANO搭建的无线通信系统 PS2教程:http://bbs.elecfans.com/jishu_455271_1_1.html
PS2程序: [mw_shl_code=cpp,true]#include <PS2X_lib.h> //for v1.6
#define LM1 3//PWM
#define LM2 2
#define LM3 4
#define LM4 5//PWM
#define RM1 6//PWM
#define RM2 7
#define RM3 8
#define RM4 9//PWM
#define Arms A0
PS2X ps2x; // create PS2 Controller Class
//right now, the library does NOT support hot pluggable controllers, meaning
//you must always either restart your Arduino after you conect the controller,
//or call config_gamepad(pins) again after connecting the controller.
int error = 0;
byte type = 0;
byte vibrate = 0;
void setup(){
Serial.begin(57600);
//CHANGES for v1.6 HERE!!! **************PAY ATTENTION*************
error = ps2x.config_gamepad(13,11,10,12, true, true); //setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
if(error == 0){
Serial.println("Found Controller, configured successful");
Serial.println("Try out all the buttons, X will vibrate the controller, faster as you press harder;");
Serial.println("holding L1 or R1 will print out the analog stick values.");
Serial.println("Go to www.billporter.info for updates and to report bugs.");
}
else if(error == 1)
Serial.println("No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips");
else if(error == 2)
Serial.println("Controller found but not accepting commands. see readme.txt to enable debug. Visit www.billporter.info for troubleshooting tips");
else if(error == 3)
Serial.println("Controller refusing to enter Pressures mode, may not support it. ");
//Serial.print(ps2x.Analog(1), HEX);
type = 1;
pinMode(LM1,OUTPUT);
pinMode(LM2,OUTPUT);
pinMode(LM3,OUTPUT);
pinMode(LM4,OUTPUT);
pinMode(RM1,OUTPUT);
pinMode(RM2,OUTPUT);
pinMode(RM3,OUTPUT);
pinMode(RM4,OUTPUT);
ServoInint();
pinMode(Arms,OUTPUT);
digitalWrite(Arms,LOW);
}
void loop(){
/* You must Read Gamepad to get new values
Read GamePad and set vibration values
ps2x.read_gamepad(small motor on/off, larger motor strenght from 0-255)
if you don't enable the rumble, use ps2x.read_gamepad(); with no values
you should call this at least once a second
*/
if(type==1){ //DualShock Controller
ps2x.read_gamepad(false, vibrate); //read controller and set large motor to spin at 'vibrate' speed
if(ps2x.Button(PSB_START)) //will be TRUE as long as button is pressed
{
Serial.println("Start is being held");
}
if(ps2x.Button(PSB_SELECT))
Serial.println("Select is being held");
if(ps2x.Button(PSB_PAD_UP)) { //will be TRUE as long as button is pressed
Serial.print("Up held this hard: ");
Serial.println(ps2x.Analog(PSAB_PAD_UP), DEC);
}
if(ps2x.Button(PSB_PAD_RIGHT)){
Serial.print("Right held this hard: ");
Serial.println(ps2x.Analog(PSAB_PAD_RIGHT), DEC);
}
if(ps2x.Button(PSB_PAD_LEFT)){
Serial.print("LEFT held this hard: ");
Serial.println(ps2x.Analog(PSAB_PAD_LEFT), DEC);
}
if(ps2x.Button(PSB_PAD_DOWN)){
Serial.print("DOWN held this hard: ");
Serial.println(ps2x.Analog(PSAB_PAD_DOWN), DEC);
}
vibrate = ps2x.Analog(PSAB_BLUE); //this will set the large motor vibrate speed based on
//how hard you press the blue (X) button
if (ps2x.NewButtonState()) //will be TRUE if any button changes state (on to off, or off to on)
{
if(ps2x.Button(PSB_L3))
Serial.println("L3 pressed");
if(ps2x.Button(PSB_R3))
Serial.println("R3 pressed");
if(ps2x.Button(PSB_L2))
Serial.println("L2 pressed");
if(ps2x.Button(PSB_R2))
Serial.println("R2 pressed");
if(ps2x.Button(PSB_GREEN))
Serial.println("Triangle pressed");
}
if(ps2x.ButtonPressed(PSB_RED)) //will be TRUE if button was JUST pressed
{
Serial.println("Circle just pressed");
}
if(ps2x.ButtonReleased(PSB_PINK)) //will be TRUE if button was JUST released
{
Serial.println("Square just released");
digitalWrite(Arms,HIGH);
}
if(ps2x.NewButtonState(PSB_BLUE)) //will be TRUE if button was JUST pressed OR released
{
Serial.println("X just changed");
digitalWrite(Arms,LOW);
}
if(ps2x.Button(PSB_L1) || ps2x.Button(PSB_R1)) // print stick values if either is TRUE
{
Serial.print("Stick Values:");
Serial.print(ps2x.Analog(PSS_LY), DEC); //Left stick, Y axis. Other options: LX, RY, RX
if(ps2x.Analog(PSS_LY)<127)Forward2(map(ps2x.Analog(PSS_LY),126,0,0,255));
else if(ps2x.Analog(PSS_LY)>127)Back2();
else Stop2();
Serial.print(",");
Serial.print(ps2x.Analog(PSS_LX), DEC);
Serial.print(",");
Serial.print(ps2x.Analog(PSS_RY), DEC);
if(ps2x.Analog(PSS_RY)<127)Forward1(map(ps2x.Analog(PSS_RY),126,0,0,255));
else if(ps2x.Analog(PSS_RY)>127)Back1();
else Stop1();
Serial.print(",");
Serial.println(ps2x.Analog(PSS_RX), DEC);
}
else Stop();
}
delay(50);
}
void ServoInint()
{
digitalWrite(LM1,LOW);
digitalWrite(LM2,LOW);
digitalWrite(LM3,LOW);
digitalWrite(LM4,LOW);
digitalWrite(RM1,LOW);
digitalWrite(RM2,LOW);
digitalWrite(RM3,LOW);
digitalWrite(RM4,LOW);
}
void Forward1(int speed1)
{
analogWrite(LM1,speed1);
digitalWrite(LM2,LOW);
digitalWrite(LM3,LOW);
analogWrite(LM4,speed1);
}
void Forward2(int speed2)
{
analogWrite(RM1,speed2);
digitalWrite(RM2,LOW);
digitalWrite(RM3,LOW);
analogWrite(RM4,speed2);
}
void Back1()
{
digitalWrite(LM1,LOW);
digitalWrite(LM2,HIGH);
digitalWrite(LM3,HIGH);
digitalWrite(LM4,LOW);
}
void Back2()
{
digitalWrite(RM1,LOW);
digitalWrite(RM2,HIGH);
digitalWrite(RM3,HIGH);
digitalWrite(RM4,LOW);
}
void Stop()
{
Stop1();
Stop2();
}
void Stop1()
{
digitalWrite(LM1,HIGH);
digitalWrite(LM2,HIGH);
digitalWrite(LM3,LOW);
digitalWrite(LM4,LOW);
}
void Stop2()
{
digitalWrite(RM1,HIGH);
digitalWrite(RM2,HIGH);
digitalWrite(RM3,LOW);
digitalWrite(RM4,LOW);
}
[/mw_shl_code]
在调试机器的过程中,发现NANO板发热,原因是整个机器只有一个电池供电,895电机和两个减速电机运行时电流比较大,产生的热量也比较大。最后还是将NANO板单独用一个9V电池供电(将锂电池的电压经过压降板供电也可以)。
这里做一个个人小结,这次比赛准备相当不充分,整个机器人需要改进的地方很多,问题也很多。不过制作机器人也让我收获了一些东西,重新理解了格斗机器人的定义。很遗憾这次比赛没有去比赛现场,没能见识各位大佬的风姿,希望下次能有机会现场观看,大饱眼福。
附上30秒被KO的视频 *************************************************************** *********************************************** ******************************* ***************** ***** END!? 留个彩蛋 |