logo

想问openmv拍到的圆形坐标和距离Arduino为什么接受不了,缺了什么?

2020-08-01 11:39
8
_3smw
38ea87ab-00fa-4b82-b949-e0281f10c24d.png

再发一下Arduino代码求大神大哥们教教

#include <Servo.h>

#include <math.h>

#include <SoftwareSerial.h>

SoftwareSerial softSerial(10, 11);

volatile float cx;

volatile float cy;

volatile float cl;

float p[3];

float pos1=0;

float pos3=0;

float z=0;

float k=0;

String json;

Servo myservo1,myservo2,myservo3,myservo4;

void setup()

{

cx=0;

cy=0;

cl=0;

Serial.begin(9600);

softSerial.begin(9600);

myservo1.attach(2);

myservo2.attach(4);

myservo3.attach(7);

myservo4.attach(8);

}

void loop()

{

if (softSerial.available()>0)

{

p[3]=float(softSerial.read());

}

cl=p[0];

cx=p[1];

cy=p[2];

z=sqrt(cl*cl-cx*cx-cy*cy);

pos1=(atan(cx/(23+z))*180)/3.1415926;

k=sqrt((z+23)*(z+23)+cx*cx);

pos3=(atan(cy/k)*180)/3.1415926;

delay(5000);

myservo1.write(pos1);

myservo2.write(90);

myservo3.write(pos3);

myservo4.write(180);

Serial.println(p[0]);

}

2020-08-01 18:55
I
网红小智智 星瞳科技

https://book.openmv.cc/MCU/serial2.html

按照这个的代码改一下。

2020-08-01 20:32
8
_3smw

我已经知道是因为p的坐标值是字符串了,就是不知道怎么把他换成整形

2020-08-03 10:22
I
网红小智智 星瞳科技

看我上面的链接。string.toInt()方法。