7552浏览
查看: 7552|回复: 1

[讨论] 【CurieNano试用】机器人调试助手

[复制链接]
【CurieNano试用】机器人调试助手


一个有趣的【神经元自动计算】的现象:
【CurieNano试用】机器人调试助手图17
找衣架,晾衣服
~每次从洗衣机里取出一堆衣服后,

再去寻找衣架(有的直接拿来,有的是退下干净衣服取出)
的数量与衣服的数量误差常常为0最多为1。
【~全程根本没数过!没数过!没数过!
科学家们正在研学神经元的种种功能应用于智慧机器人,
这会不会改变全世界呢?!
【特此声明:本文与神经元没有什么关联...】
【但恳请知晓Curie与神经元相关内容者能够提示一二:handshake谢谢
---------------------------------------------------------------------

CurieNano功能强大,我却仅能用之极少!:funk:
我的一点儿想法:
在手机上接收机器人的实时数据,并能无线控制它。
比如以下纸盒游戏机器人的姿态数据:


----------------所需材料---------------
一、机器人结构件:
【舵机*4、多功能支架*4、长U支架*2、U型梁*2、L型*1、大脚板*2等】
【CurieNano试用】机器人调试助手图10

【CurieNano试用】机器人调试助手图1

【CurieNano试用】机器人调试助手图11

二、控制器:
【CurieNano试用】机器人调试助手图4

【CurieNano试用】机器人调试助手图3
【CurieNano试用】机器人调试助手图2
三、电源:
【7.4V、3.7V】
【CurieNano试用】机器人调试助手图9

【CurieNano试用】机器人调试助手图7

四、通讯模块:
【如果完全搞清了以上控制器蓝牙通信,以下可免】
蓝牙HC06*1、ZIGBEE*2
【CurieNano试用】机器人调试助手图6

五、其它【安卓手机、面包板、接头、开关、杜邦线等】
【CurieNano试用】机器人调试助手图5

【CurieNano试用】机器人调试助手图8

【CurieNano试用】机器人调试助手图16

--------------------模块化工程--------------------
模块一】、机器人结构定型组装【主要是我儿子完成】
【CurieNano试用】机器人调试助手图12

【CurieNano试用】机器人调试助手图13

【模块二】、了解CurireNano的官方文档资料、
理解其基本功能及代码实现【耗时最多】
  1. // 05/25/2017
  2.   /*
  3.     The orientations of the board:
  4.         0:处理器平面--朝上
  5.         1:处理器平面--朝下
  6.         2:模拟针脚侧--朝下
  7.         3:模拟针脚侧--朝上
  8.         4:USB接口-----朝上
  9.         5:USB接口-----朝下
  10.     0: flat, processor facing up
  11.     1: flat, processor facing down
  12.     2: landscape, analog pins down
  13.     3: landscape, analog pins up
  14.     4: portrait, USB connector up
  15.     5: portrait, USB connector down
  16.   */
  17. #include <CurieIMU.h>
  18. #include <MadgwickAHRS.h>
  19. #include <SoftwareSerial.h>
  20. SoftwareSerial mySerial(2, 3); // RX, TX
  21. Madgwick filter;
  22. unsigned long microsPerReading, microsPrevious;
  23. float accelScale, gyroScale;
  24. int lastOrientation = - 1; // previous orientation (for comparison)
  25. void setup() {
  26.   Serial1.begin(9600);
  27.   mySerial.begin(9600);
  28.   while (!Serial1);    // wait for the Serial1 port to open
  29.   // initialize device
  30.   Serial1.println("初始化 IMU 设备...");
  31.   // start the IMU and filter
  32.   CurieIMU.begin();
  33.   CurieIMU.setGyroRate(25);
  34.   CurieIMU.setAccelerometerRate(25);
  35.   filter.begin(25);
  36.   // Set the accelerometer range to 2G
  37.   CurieIMU.setAccelerometerRange(2);
  38.   // Set the gyroscope range to 250 degrees/second
  39.   CurieIMU.setGyroRange(250);
  40.   // initialize variables to pace updates to correct rate
  41.   microsPerReading = 1000000 / 25;
  42.   microsPrevious = micros();
  43. }
  44. void loop() {
  45.   
  46.   int aix, aiy, aiz;
  47.   int gix, giy, giz;
  48.   float ax, ay, az;
  49.   float gx, gy, gz;
  50.   float roll, pitch, heading;
  51.   unsigned long microsNow;
  52.   
  53.   int orientation = - 1;   // the board's orientation
  54.   String orientationString; // string for printing description of orientation
  55.   // check if it's time to read data and update the filter
  56.   microsNow = micros();
  57.   if (microsNow - microsPrevious >= microsPerReading) {
  58.     // read raw data from CurieIMU
  59.     CurieIMU.readMotionSensor(aix, aiy, aiz, gix, giy, giz);
  60.     // convert from raw data to gravity and degrees/second units
  61.     ax = convertRawAcceleration(aix);
  62.     ay = convertRawAcceleration(aiy);
  63.     az = convertRawAcceleration(aiz);
  64.     gx = convertRawGyro(gix);
  65.     gy = convertRawGyro(giy);
  66.     gz = convertRawGyro(giz);
  67.   // read accelerometer:
  68.   int x = CurieIMU.readAccelerometer(X_AXIS);
  69.   int y = CurieIMU.readAccelerometer(Y_AXIS);
  70.   int z = CurieIMU.readAccelerometer(Z_AXIS);
  71.   // calculate the absolute values, to determine the largest
  72.   int absX = abs(x);
  73.   int absY = abs(y);
  74.   int absZ = abs(z);
  75.   if ( (absZ > absX) && (absZ > absY)) {
  76.       // base orientation on Z
  77.       if (z > 0) {
  78.         orientationString = "处理器平面--朝上";
  79.         orientation = 0;  
  80.       } else {
  81.         orientationString = "处理器平面--朝下";
  82.         orientation = 1;
  83.       }
  84.     } else if ( (absY > absX) && (absY > absZ)) {
  85.       // base orientation on Y
  86.       if (y > 0) {
  87.         orientationString = "数字 Pin 侧--朝上";
  88.         orientation = 2;
  89.       } else {
  90.         orientationString = "模拟 Pin 侧--朝上";
  91.         orientation = 3;
  92.       }
  93.     } else {
  94.       // base orientation on X
  95.       if (x < 0) {
  96.         orientationString = "USB 接口--朝上";
  97.         orientation = 4;
  98.       } else {
  99.         orientationString = "USB 接口--朝下";
  100.         orientation = 5;
  101.       }
  102.   }
  103.     // update the filter, which computes orientation
  104.     filter.updateIMU(gx, gy, gz, ax, ay, az);
  105.     // print the heading, pitch and roll
  106.     roll = filter.getRoll();
  107.     pitch = filter.getPitch();
  108.     heading = filter.getYaw();
  109.     Serial1.println("-----------------------------");
  110.     Serial1.print("heading: ");
  111.     Serial1.println(heading);
  112.     Serial1.print(" pitch: ");
  113.     Serial1.println(pitch);
  114.     Serial1.print("     roll: ");
  115.     Serial1.println(roll);
  116.     Serial1.println("-----------------------------");
  117.     // if the orientation has changed, print out a description:
  118.     //if (orientation != lastOrientation) {
  119.       Serial1.println(orientationString);
  120.       Serial1.println("-----------------------------");
  121.       lastOrientation = orientation;
  122.     //}
  123.     delay(300);
  124.     // increment previous time, so we keep proper pace
  125.     microsPrevious = microsPrevious + microsPerReading;
  126.   }
  127.   if (Serial1.available())  // 手机蓝牙向CurieNano101硬串口(0,1)发来的命令,
  128.     mySerial.write(Serial1.read()); // 通过串口(2,3)转发出去
  129.   
  130. } // end loop
  131. /////////////////////////////////////////////////
  132. float convertRawAcceleration(int aRaw) {
  133.   // since we are using 2G range
  134.   // -2g maps to a raw value of -32768
  135.   // +2g maps to a raw value of 32767
  136.   
  137.   float a = (aRaw * 2.0) / 32768.0;
  138.   return a;
  139. }
  140. ///////////////////////////////////////////////
  141. float convertRawGyro(int gRaw) {
  142.   // since we are using 250 degrees/seconds range
  143.   // -250 maps to a raw value of -32768
  144.   // +250 maps to a raw value of 32767
  145.   
  146.   float g = (gRaw * 250.0) / 32768.0;
  147.   return g;
  148. }
  149. ///////////////////////////////////////////////[/mw_shl_code]
  150. 【模块三】、舵机控制器接收串口命令并执行
  151. [mw_shl_code=cpp,true]// 05/26/2017 OK ^-^
  152. #include <Servo.h>
  153. Servo myServoA;
  154. Servo myServoB;
  155. Servo myServoC;
  156. Servo myServoD;
  157. int valueOfAngle = 0;  
  158. String servoString = "";
  159. /////////////////////////////////////////////////////
  160. void setup() {
  161.   // put your setup code here, to run once:
  162.   Serial.begin(9600);
  163.   while (!Serial) {
  164.     ;
  165.   }
  166.   pinMode(13,OUTPUT);
  167.   
  168.   myServoA.attach(5);
  169.   myServoB.attach(6);
  170.   myServoC.attach(9);
  171.   myServoD.attach(10);
  172.   
  173.   digitalWrite(13,HIGH);// 舵机重置归中
  174.   myServoA.write(90);
  175.   delay(300);
  176.   myServoB.write(90);
  177.   delay(300);
  178.   myServoC.write(90);
  179.   delay(300);
  180.   myServoD.write(90);
  181.   delay(300);
  182.   digitalWrite(13,LOW);
  183. }
  184. /////////////////////////////////////////////////////
  185. void loop() {
  186.   while (Serial.available() > 0) {
  187.     servoString = Serial.readString();
  188.     if (servoString.startsWith("A")) {
  189.       servoString = servoString.substring(1);
  190.       myServoA.write(servoString.toInt());
  191.       delay(500);
  192.     }else if(servoString.startsWith("B")) {
  193.       servoString = servoString.substring(1);
  194.       myServoB.write(servoString.toInt());
  195.       delay(500);
  196.     }else if(servoString.startsWith("C")) {
  197.       servoString = servoString.substring(1);
  198.       myServoC.write(servoString.toInt());
  199.       delay(500);
  200.     }else if(servoString.startsWith("D")) {
  201.       servoString = servoString.substring(1);
  202.       myServoD.write(servoString.toInt());
  203.       delay(500);
  204.     } // end if
  205.     servoString = "";
  206.   } // end while
  207. } // end loop
  208. /////////////////////////////////////////////////////
复制代码


【模块四】、安卓手机APP【蓝牙通讯】
实现无线接收数据与发送命令
【CurieNano试用】机器人调试助手图18
【手机APP界面】

手机APP编译代码:
【CurieNano试用】机器人调试助手图19

【CurieNano试用】机器人调试助手图20

附:四自由度机器人全身照
【CurieNano试用】机器人调试助手图14

【CurieNano试用】机器人调试助手图15

xar  初级技匠

发表于 2017-9-19 09:34:22

小黑金刚~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail