OTTO机器人之避障功能实现
【摘要】
#include <Servo.h>
#include <Oscillator.h>
#include <US.h>
#include <Otto.h>
...
#include <Servo.h>
#include <Oscillator.h>
#include <US.h>
#include <Otto.h>
/*
---------------
| O O |
|---------------|
RIGHT LEG 3==> | | <== LEFT LEG 2
---------------
|| ||
RIGHT FOOT 5==> ----- ------ <== LEFT FOOT 4
|----- ------|
*/
#define PIN_LEFT_LEG 2
#define PIN_RIGHT_LEG 3
#define PIN_LEFT_FOOT 4
#define PIN_RIGHT_FOOT 5
#define TRIM_LEFT_LEG 0
#define TRIM_RIGHT_LEG 0
#define TRIM_LEFT_FOOT 0
#define TRIM_RIGHT_FOOT 0
Otto Otto; //This is Otto!
void setup()
{
Serial.begin(9600);
Serial.println("hello");
//Set the servo pins
Otto.init(PIN_LEFT_LEG,PIN_RIGHT_LEG,PIN_LEFT_FOOT,PIN_RIGHT_FOOT,true);
Otto.setTrims(TRIM_LEFT_LEG,TRIM_RIGHT_LEG, TRIM_LEFT_FOOT, TRIM_RIGHT_FOOT);
Otto.sing(S_connection); //Otto wake up!
Otto.home();
}
///////////////////////////////////////////////////////////////////
//-- Principal Loop ---------------------------------------------//
///////////////////////////////////////////////////////////////////
void loop()
{
bool obstacleDetected = false;
obstacleDetected = obstacleDetector();
if(obstacleDetected)
{
Otto.sing(S_surprise);
Otto.walk(7,1000,BACKWARD);
delay(1000);
Otto.sing(S_happy);
Otto.turn(10,1000,RIGHT);
delay(2000);
}
else
{
Otto.walk(1,1000,FORWARD);
}
}
///////////////////////////////////////////////////////////////////
//-- Function to read distance sensor & to actualize obstacleDetected variable
bool obstacleDetector()
{
int distance = Otto.getDistance();
Serial.println(distance);
if(distance<15)
{
return true;
}
else
{
return false;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
文章来源: recclay.blog.csdn.net,作者:ReCclay,版权归原作者所有,如需转载,请联系作者。
原文链接:recclay.blog.csdn.net/article/details/82710155
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)