本文示例将实现R329样机机器鸟扇动翅膀的功能。
鸟类的翅膀主要由肩关节、肘关节、腕关节组成,本样机利用组合机构设计机器鸟的扑翼机构。
拥有两个关节的机器鸟扑翼机构结构图
单侧翅膀
双翅
尾部
整机
电路连接:将舵机连接在Bigfish扩展板的D3端口。
编程环境:Arduino 1.8.19
下面提供一个机器鸟扇动翅膀的参考例程(Bird_Wing_Fly.ino),实验效果可参考演示视频。
/*------------------------------------------------------------------------------------ 版权说明:Copyright 2023 Robottime(Beijing) Technology Co., Ltd. All Rights Reserved. Distributed under MIT license.See file LICENSE for detail or copy at https://opensource.org/licenses/MIT by 机器谱 2023-05-24 https://www.robotway.com/ ------------------------------*/ #include程序源代码及样机3D文件详见 机器鸟-扇动翅膀int _ABVAR_1_Subdivision_number = 0 ; int _ABVAR_2_Flags = 0 ; Servo servo_pin_3; int _ABVAR_3_Servo3_Start = 0 ; int _ABVAR_4_Servo3_End = 0 ; int _ABVAR_5_Angle_Of_Each_Time = 0 ; int _ABVAR_6_value1 = 0 ; int _ABVAR_7_Angle_Of_Change = 0 ; int _ABVAR_8_value2 = 0 ; void Wing_Open(); void Wing_Close(); void setup() { servo_pin_3.attach(3); _ABVAR_1_Subdivision_number = 14 ; _ABVAR_2_Flags = 0 ; servo_pin_3.write( 80 ); delay( 1000 ); } void loop() { Wing_Close(); Wing_Open(); } void Wing_Close() { _ABVAR_3_Servo3_Start = 10 ; _ABVAR_4_Servo3_End = 80 ; _ABVAR_5_Angle_Of_Each_Time = ( abs( ( _ABVAR_3_Servo3_Start - _ABVAR_4_Servo3_End ) ) / _ABVAR_1_Subdivision_number ) ; if (( ( ( _ABVAR_3_Servo3_Start - _ABVAR_4_Servo3_End ) ) > ( 1 ) )) { _ABVAR_2_Flags = -1 ; } else { _ABVAR_2_Flags = 1 ; } for (_ABVAR_6_value1= 1; _ABVAR_6_value1<= ( ( _ABVAR_1_Subdivision_number + 1 ) ); _ABVAR_6_value1++ ) { _ABVAR_7_Angle_Of_Change = ( _ABVAR_3_Servo3_Start + ( _ABVAR_5_Angle_Of_Each_Time * _ABVAR_2_Flags ) ) ; servo_pin_3.write( _ABVAR_7_Angle_Of_Change ); _ABVAR_3_Servo3_Start = _ABVAR_7_Angle_Of_Change ; delay( 28 ); } } void Wing_Open() { _ABVAR_3_Servo3_Start = 80 ; _ABVAR_4_Servo3_End = 10 ; _ABVAR_5_Angle_Of_Each_Time = ( abs( ( _ABVAR_3_Servo3_Start - _ABVAR_4_Servo3_End ) ) / _ABVAR_1_Subdivision_number ) ; if (( ( ( _ABVAR_3_Servo3_Start - _ABVAR_4_Servo3_End ) ) > ( 1 ) )) { _ABVAR_2_Flags = -1 ; } else { _ABVAR_2_Flags = 1 ; } for (_ABVAR_8_value2= 1; _ABVAR_8_value2<= ( ( _ABVAR_1_Subdivision_number + 1 ) ); _ABVAR_8_value2++ ) { _ABVAR_7_Angle_Of_Change = ( _ABVAR_3_Servo3_Start + ( _ABVAR_5_Angle_Of_Each_Time * _ABVAR_2_Flags ) ) ; servo_pin_3.write( _ABVAR_7_Angle_Of_Change ); _ABVAR_3_Servo3_Start = _ABVAR_7_Angle_Of_Change ; delay( 65 ); } }