3xmaker,人机协作共融万物互联,柔性可穿戴人机交互感知与测量!

  1. 设计指南
  2. |
  3. 新品速递
  4. |
  5. 联系我们
机器人+
传感器+
柔性/印刷电子+
增强现实+
人机交互感知+
网站首页
/
智造案例
/
智造

镭射激光逗猫神器

来源:3XMaker   发布时间:2019年03月26日

镭射激光逗猫神器

http://www.3xmaker.com/UploadFiles/2019-03/20193263218123754.jpg

喵星人对于激光发射器发出的光点有着天生、难以抗拒的执着。它们就像一个个职业杀手一样直接的扑向那个小小的红色激光点。对于猫咪们来说狩猎是一项很好的运动。看着萌宠们发起攻击的样子,作为铲屎官的你会不会觉得是一件饶有兴趣的事情呢!通常你只要拿起你的激光发射器就可以做到,但是你总会预先知道激光点的方向。让我们给这个游戏制造一些混乱元素——可以平面移动或改变仰角的激光炮塔,并让它可以周期性地随机移动。先看看下面的视频~

第一步:准备项目组件清单

它需要用你惯用的任何舵机来配合驱动塔楼。这里有两种方案:
RobotGeek 云台:
如果你喜好添加一个摄像头或者附加一个的自带钓鱼杆的逗猫玩具,这款将是一个好的选择。

RobotGeek云台和舵机

镭射激光发射器和固定配件

Geekduino或者其他兼容Arduino UNO 开发板

传感器模块 (推荐,可简化接线)

7V 5A 电源

Mini 云台:
不错的低成本选择, 但是9G 的舵机输出的力量有限。

Mini 云台套件

9G 舵机 x 2

镭射激光发射器和固定配件

Geekduino或者其他兼容Arduino UNO 开发板

传感器模块 (推荐,可使简化接线)

6V 2A电源

第二步:组装炮塔

http://www.3xmaker.com/UploadFiles/2019-03/20193264186180223.jpg
如果你使用的是RobotGeek云台,安装说明可以在这找到
如果你使用的是Mini云台, 安装说明可以在这找到
拿上激光发射器,让我们把它连接起来。

第三步:接线

http://www.3xmaker.com/UploadFiles/2019-03/20193261239017874.jpg

设备

引脚类型

引脚编号

平移舵机

数字

10

仰角舵机

数字

11

激光发射器

数字

2

确保设定的输入电压能供更大的伺服7v运行。对于9G的伺服系统,你可以用5V6V的电源。真的是超级简单的接线。赶紧编码起来吧!

第四步:编程

上传以下代码到你的 Arduino 主板上。

帮助

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

86

87

88

89

90

91

92

//https://github.com/robotgeek/desktopRoboTurretV3/tree/master/roboTurret3_lazerDazer

//Includes

#include   <Servo.h>            //include the servo library for working with servo objects

 

//Defines

const int PAN =   10;         //Pan Servo Digital Pin

const int TILT =   11;        //Tilt Servo Digital Pin

const int LASER =   2;        //Laser Digital Pin

const int PAN_MIN =   40;     // minimum pan servo range, value should be   between 0 and 180 and lower than PAN_MAX

const int PAN_MAX =   140;    // maximum pan servo range, value should be between 0   and 180 and more than PAN_MIN

const int TILT_MIN =   60;    // minimum tilt servo range, value should be between 0   and 180 and lower than TILT_MAX

const int TILT_MAX = 100;   //   maximum tilt servo range, value should be between 0 and 180 and more than   TILT_MIN

const int SPEED_MIN = 10;   //   minimum interpolation speed (less than 5 not recommended)

const int SPEED_MAX = 10;   //   maximum interpolation speed (Lower SPEED_MAX values mean that the program   will cycle more quickly, leading to an increased occurance of pausing. Adjust   ROLL_MAX accordingly)

const int ROLL_MAX =   40;    // Roll the dice for random pause. Lower value = more   frequent pauses, higher value = less frequent pauses

const int PAUSE_MIN = 500;  //   define minimum pause length in mS. 1000 = 1 second

const int PAUSE_MAX = 1500; // define   maximum pause length in mS.

 

Servo panServo, tiltServo;  //   create servo objects to control the pan and tilt servos

 

long dazer_speed;

int dazer_pause_roll;

int pause_length = 1;

 

int panValue = 90;   //current   positional value being sent to the pan servo.

int tiltValue = 90;  //current   positional value being sent to the tilt servo.

byte pan_goal;

byte tilt_goal;

 

//State Variables

int laserState =   LOW;         //The current state of   the laser module

 

//Timing variables

long lastDebounceTime = 0;  // the   last time the output pin was toggled. This variable is a 'long' because it   may need to hold many milliseconds, and a 'long' will afford more space than   an 'int'

int debounceDelay = 50;      // the amount of time that that a button must be held, for a reading to   register (in milliseconds)

 

void setup()

{

  //initialize servos

  panServo.attach(PAN);    // attaches/activates the pan servo on pin PAN

  tiltServo.attach(TILT);    // attaches/activates the tilt servo on pin TILT

 

  //initalize digital pins

  pinMode(LASER,   OUTPUT);      //set the LASER Pin to an output

   

  //write initial servo   positions to set the servos to 'home'

  panServo.write(panValue);    //sets the pan servo position to the default 'home' value

  tiltServo.write(tiltValue);//sets   the tilt servo position to the default 'home' value

   

  randomSeed(analogRead(0));    //set a basis for the random() engine, based off of analog0 which will be a random   number because nothing is attached

 

  digitalWrite(LASER, HIGH);

}

 

void loop()

{

  dazer_pause_roll = random(1,   ROLL_MAX);      //pick a random number between 1 and   ROLL_MAX

  pause_length =   random(PAUSE_MIN, PAUSE_MAX); //pick a random number between PAUSE_MIN and   PAUSE_MAX

  delay(pause_length);                           //use the random number to pause for pause_length milliseconds

 

  pan_goal = random(PAN_MIN,   PAN_MAX);

  tilt_goal = random(TILT_MIN,   TILT_MAX);

  dazer_speed =   random(SPEED_MIN, SPEED_MAX);

  //perfom the loop while the   current positions are different from the goal positions

 

  //if the pan_goal is larger   than the pan position, move the pan position up

  if (pan_goal > panValue)

  {

    panValue = panValue++;

  }

   

  //if the pan_goal is smaller   than the pan position, move the pan position down

  else if (pan_goal <   panValue)

  {

    panValue =   panValue--;

  }                

   

  //if the tilt_goal is larger   than the tilt position, move the pan position up

  if (tilt_goal > tiltValue)

  {

    tiltValue =   tiltValue++;

  }

  //if the tilt_goal is smaller   than the tilt position, move the pan position down

  else if (tilt_goal <   tiltValue)

  {

    tiltValue =   tiltValue--;

  }   

   

  panServo.write(pan_goal);                      // sets the servo position according to the scaled value

  tiltServo.write(tilt_goal);                    // sets the servo position according to the scaled value

  delay(dazer_speed);                            // waits for a random delay before the next loop

} //end loop()

把你的猫咪萌宠抓过来,开启它吧!(当然是开启你的塔楼啦,而不是你的猫咪啦!)你的萌宠可是自带电源的哦!可不要尝试给你的猫咪充电哦!

第五步:Done!就是这么完美!

现在铲屎的你只需坐下来,看着你的猫咪追逐和攻击那个邪恶的小红点啦!

 


上一篇:万物音乐盒子:让日常物品发声的电子鼓
下一篇:选择困难症福音: DIY“囚徒困境”抢答器

南京合越智能,增强智造,增强感知,增强交互!

业务合作

(我们会第一时间与您联系)

联系方式

  1. 微信:13815863530(手机同号)
  2. QQ:38260484
  3. 3XMaker@163.com
Copyright@ 2016-2025 南京合越智能科技有限公司 苏ICP备18068961号