一个有趣的【神经元自动计算】的现象:
【找衣架,晾衣服】
~每次从洗衣机里取出一堆衣服后,
再去寻找衣架(有的直接拿来,有的是退下干净衣服取出)
的数量与衣服的数量误差常常为0最多为1。
【~全程根本没数过!没数过!没数过!】
科学家们正在研学神经元的种种功能应用于智慧机器人,
这会不会改变全世界呢?!
【特此声明:本文与神经元没有什么关联...】
【但恳请知晓Curie与神经元相关内容者能够提示一二:handshake谢谢 】
---------------------------------------------------------------------
CurieNano功能强大,我却仅能用之极少!:funk:
我的一点儿想法:
在手机上接收机器人的实时数据,并能无线控制它。
比如以下纸盒游戏机器人的姿态数据:
----------------所需材料---------------
一、机器人结构件: 【舵机*4、多功能支架*4、长U支架*2、U型梁*2、L型*1、大脚板*2等】
二、控制器:
三、电源: 【7.4V、3.7V】
四、通讯模块: 【如果完全搞清了以上控制器蓝牙通信,以下可免】 蓝牙HC06*1、ZIGBEE*2
五、其它【安卓手机、面包板、接头、开关、杜邦线等】
--------------------模块化工程-------------------- 【模块一】、机器人结构定型组装【主要是我儿子完成】
【模块二】、了解CurireNano的官方文档资料、 理解其基本功能及代码实现【耗时最多】
- // 05/25/2017
- /*
- The orientations of the board:
- 0:处理器平面--朝上
- 1:处理器平面--朝下
- 2:模拟针脚侧--朝下
- 3:模拟针脚侧--朝上
- 4:USB接口-----朝上
- 5:USB接口-----朝下
- 0: flat, processor facing up
- 1: flat, processor facing down
- 2: landscape, analog pins down
- 3: landscape, analog pins up
- 4: portrait, USB connector up
- 5: portrait, USB connector down
- */
- #include <CurieIMU.h>
- #include <MadgwickAHRS.h>
- #include <SoftwareSerial.h>
-
- SoftwareSerial mySerial(2, 3); // RX, TX
-
- Madgwick filter;
- unsigned long microsPerReading, microsPrevious;
- float accelScale, gyroScale;
- int lastOrientation = - 1; // previous orientation (for comparison)
-
- void setup() {
- Serial1.begin(9600);
- mySerial.begin(9600);
- while (!Serial1); // wait for the Serial1 port to open
- // initialize device
- Serial1.println("初始化 IMU 设备...");
- // start the IMU and filter
- CurieIMU.begin();
- CurieIMU.setGyroRate(25);
- CurieIMU.setAccelerometerRate(25);
- filter.begin(25);
-
- // Set the accelerometer range to 2G
- CurieIMU.setAccelerometerRange(2);
- // Set the gyroscope range to 250 degrees/second
- CurieIMU.setGyroRange(250);
-
- // initialize variables to pace updates to correct rate
- microsPerReading = 1000000 / 25;
- microsPrevious = micros();
- }
-
- void loop() {
-
- int aix, aiy, aiz;
- int gix, giy, giz;
- float ax, ay, az;
- float gx, gy, gz;
- float roll, pitch, heading;
- unsigned long microsNow;
-
- int orientation = - 1; // the board's orientation
- String orientationString; // string for printing description of orientation
-
- // check if it's time to read data and update the filter
- microsNow = micros();
- if (microsNow - microsPrevious >= microsPerReading) {
-
- // read raw data from CurieIMU
- CurieIMU.readMotionSensor(aix, aiy, aiz, gix, giy, giz);
-
- // convert from raw data to gravity and degrees/second units
- ax = convertRawAcceleration(aix);
- ay = convertRawAcceleration(aiy);
- az = convertRawAcceleration(aiz);
- gx = convertRawGyro(gix);
- gy = convertRawGyro(giy);
- gz = convertRawGyro(giz);
-
- // read accelerometer:
- int x = CurieIMU.readAccelerometer(X_AXIS);
- int y = CurieIMU.readAccelerometer(Y_AXIS);
- int z = CurieIMU.readAccelerometer(Z_AXIS);
- // calculate the absolute values, to determine the largest
- int absX = abs(x);
- int absY = abs(y);
- int absZ = abs(z);
-
- if ( (absZ > absX) && (absZ > absY)) {
- // base orientation on Z
- if (z > 0) {
- orientationString = "处理器平面--朝上";
- orientation = 0;
- } else {
- orientationString = "处理器平面--朝下";
- orientation = 1;
- }
- } else if ( (absY > absX) && (absY > absZ)) {
- // base orientation on Y
- if (y > 0) {
- orientationString = "数字 Pin 侧--朝上";
- orientation = 2;
- } else {
- orientationString = "模拟 Pin 侧--朝上";
- orientation = 3;
- }
- } else {
- // base orientation on X
- if (x < 0) {
- orientationString = "USB 接口--朝上";
- orientation = 4;
- } else {
- orientationString = "USB 接口--朝下";
- orientation = 5;
- }
- }
-
- // update the filter, which computes orientation
- filter.updateIMU(gx, gy, gz, ax, ay, az);
-
- // print the heading, pitch and roll
- roll = filter.getRoll();
- pitch = filter.getPitch();
- heading = filter.getYaw();
- Serial1.println("-----------------------------");
- Serial1.print("heading: ");
- Serial1.println(heading);
- Serial1.print(" pitch: ");
- Serial1.println(pitch);
- Serial1.print(" roll: ");
- Serial1.println(roll);
- Serial1.println("-----------------------------");
-
- // if the orientation has changed, print out a description:
- //if (orientation != lastOrientation) {
- Serial1.println(orientationString);
- Serial1.println("-----------------------------");
- lastOrientation = orientation;
- //}
- delay(300);
- // increment previous time, so we keep proper pace
- microsPrevious = microsPrevious + microsPerReading;
- }
-
- if (Serial1.available()) // 手机蓝牙向CurieNano101硬串口(0,1)发来的命令,
- mySerial.write(Serial1.read()); // 通过串口(2,3)转发出去
-
-
- } // end loop
- /////////////////////////////////////////////////
- float convertRawAcceleration(int aRaw) {
- // since we are using 2G range
- // -2g maps to a raw value of -32768
- // +2g maps to a raw value of 32767
-
- float a = (aRaw * 2.0) / 32768.0;
- return a;
- }
- ///////////////////////////////////////////////
- float convertRawGyro(int gRaw) {
- // since we are using 250 degrees/seconds range
- // -250 maps to a raw value of -32768
- // +250 maps to a raw value of 32767
-
- float g = (gRaw * 250.0) / 32768.0;
- return g;
- }
- ///////////////////////////////////////////////[/mw_shl_code]
-
- 【模块三】、舵机控制器接收串口命令并执行
- [mw_shl_code=cpp,true]// 05/26/2017 OK ^-^
- #include <Servo.h>
- Servo myServoA;
- Servo myServoB;
- Servo myServoC;
- Servo myServoD;
-
- int valueOfAngle = 0;
- String servoString = "";
- /////////////////////////////////////////////////////
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600);
- while (!Serial) {
- ;
- }
- pinMode(13,OUTPUT);
-
- myServoA.attach(5);
- myServoB.attach(6);
- myServoC.attach(9);
- myServoD.attach(10);
-
- digitalWrite(13,HIGH);// 舵机重置归中
- myServoA.write(90);
- delay(300);
- myServoB.write(90);
- delay(300);
- myServoC.write(90);
- delay(300);
- myServoD.write(90);
- delay(300);
- digitalWrite(13,LOW);
- }
- /////////////////////////////////////////////////////
- void loop() {
- while (Serial.available() > 0) {
- servoString = Serial.readString();
- if (servoString.startsWith("A")) {
- servoString = servoString.substring(1);
- myServoA.write(servoString.toInt());
- delay(500);
- }else if(servoString.startsWith("B")) {
- servoString = servoString.substring(1);
- myServoB.write(servoString.toInt());
- delay(500);
- }else if(servoString.startsWith("C")) {
- servoString = servoString.substring(1);
- myServoC.write(servoString.toInt());
- delay(500);
- }else if(servoString.startsWith("D")) {
- servoString = servoString.substring(1);
- myServoD.write(servoString.toInt());
- delay(500);
- } // end if
- servoString = "";
- } // end while
- } // end loop
- /////////////////////////////////////////////////////
复制代码
【模块四】、安卓手机APP【蓝牙通讯】 实现无线接收数据与发送命令 【手机APP界面】
手机APP编译代码:
附:四自由度机器人全身照
|
|
|
|
|
|