我是靠谱客的博主 等待奇异果,最近开发中收集的这篇文章主要介绍arduino串口绘图_有四组数据,但是为什么串口绘图器只画一个数据的图,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

请教各位大神,有四组数据,两个电位器和两个传感器,但是为什么使用串口绘图器只画一个数据的图?使用其他什么软件可以监视串口数据绘图啊?谢谢各位大神了

//PINs setting

int adjust1Pin = 15;    //用来调节A的电位器

int adjust2Pin =16;    //用来调节B的电位器

int read1Pin = 17;      //用来连接输入A传感器

int read2Pin = 18;      //用来连接输入B传感器

int i1Pin = 6;        //连接电机驱动板的I1接口

int i2Pin =9;        //连接电机驱动板的I2接口

int i3Pin = 10;        //连接电机驱动板的I3接口

int i4Pin = 11;        //连接电机驱动板的I4接口

int power1Pin = 3;     //连接电机驱动板的EA接口

int power2Pin = 5;     //连接电机驱动板的EB接口

boolean debug = false;

boolean writeLog = false;

double setKd1 =3.3;

double setKd2 =3.3;

double setKp = 1;

int offset = 70;

int delayMs = 1;

int tick = 0;

//int myLog[3500];

int *myLog = new int[3500];

//PID structure

typedef struct {

double target;

double aver;

double Kp;

double Kd;

int preError;

int power;

boolean flag;

double v;

} PID;

PID Pid1, Pid2;

void setup()

{

pinMode(i1Pin, OUTPUT);     //I1和I2都是数字信号

pinMode(i2Pin, OUTPUT);     //通过设置I1和I2来控制电流方向

pinMode(i3Pin, OUTPUT);     //I1和I2都是数字信号

pinMode(i4Pin, OUTPUT);     //通过设置I1和I2来控制电流方向

pinMode(power1Pin, OUTPUT);  //按占空比方式输出的模拟信号

pinMode(power2Pin, OUTPUT);  //按占空比方式输出的模拟信号

//analogWrite(rotatePin, 128);

Serial.begin(9600);          //设置波特率

TCCR0B = 0x01;   // Timer 0: PWM 5 &  6 @ 16 kHz

TCCR1B = 0x01;   // Timer 1: PWM 9 & 10 @ 32 kHz

TCCR2B = 0x01;   // Timer 2: PWM 3 & 11 @ 32 kHz

Pid1.Kp = setKp;

Pid1.preError = 0;

Pid1.Kd = setKd1;

Pid1.power = 0;

Pid1.flag = true;

Pid1.target = 300;

Pid1.aver = 0;

Pid1.v = 0;

Pid2.Kp = setKp;

Pid2.preError = 0;

Pid2.Kd = setKd2;

Pid2.power = 0;

Pid2.flag = true;

Pid2.target = 300;

Pid2.aver = 0;

Pid2.v = 0;

tick = 0;

}

int tick2 = 0;

//boolean rotateFlag = true;

void loop()

{

//digitalWrite(rotatePin, rotateFlag);

//rotateFlag = ! rotateFlag;

//delay(16000);

//return;

if(false) tick = 0;

tick++;

if(tick==500)

{

tick2++;

if(tick2<50) {tick = 0;return;}

tick2 = 0;

if(writeLog)

{

for(int i=0;i<500;i++)

{

Serial.print(myLog[i*7 + 0]);

Serial.print("  ");

Serial.print(myLog[i*7 + 1]);

Serial.print("  ");

Serial.print(myLog[i*7 + 2]);

Serial.print("  ");

Serial.print(myLog[i*7 + 3]);

Serial.print("  ");

Serial.print(myLog[i*7 + 4]);

Serial.print("  ");

Serial.print(myLog[i*7 + 5]);

Serial.print("  ");

Serial.print(myLog[i*7 + 6]);

Serial.println("  ");

}

Serial.println(Pid1.target);

Serial.println(Pid1.preError);

Serial.println(Pid2.target);

Serial.println(Pid2.preError);

}

return;

}

else if(tick>500)

{

tick = 0;

//delay(990000);

return;

};

//=======第一组电位器和传感器========

int readValue1 = 0;

for(int i = 0; i < 4; i++) readValue1 += analogRead(read1Pin);

readValue1 >>= 2;

//readValue1 += (Pid1.flag ? 1 : -1) * Pid1.power / 17;

int adjustValue1 = analogRead(adjust1Pin); //410 analogRead(adjust1Pin);

Pid1.aver = Pid1.aver * 0.9995 + readValue1 * 0.0005;

Pid1.target = Pid1.target + (Pid1.target - Pid1.aver) / 100.0;

Pid1.target = max(0, max(adjustValue1 - offset, Pid1.target));

Pid1.target = min(755, min(adjustValue1 + offset, Pid1.target));

//=======第二组电位器和传感器=======

int readValue2 = 0;

for(int i = 0; i < 4; i++) readValue2 += analogRead(read2Pin);

readValue2 >>= 2;

//readValue2 += (Pid2.flag ? 1 : -1) * Pid2.power / 6;

int adjustValue2 = analogRead(adjust2Pin); //240 analogRead(adjust2Pin);

Pid2.aver = Pid2.aver * 0.9995 + readValue2 * 0.0005;

Pid2.target = Pid2.target + (Pid2.target - Pid2.aver) / 1000.0;

Pid2.target = max(0, max(adjustValue2 - offset, Pid2.target));

Pid2.target = min(755, min(adjustValue2 + offset, Pid2.target));

if(true)

{

Serial.println(adjustValue1);

Serial.println(adjustValue2);

Serial.println(readValue1);

Serial.println(readValue2);

Pid1.flag = adjustValue1 > 512;

Pid1.power = abs(adjustValue1 - 512) / 2;

if(Pid1.power > 255) Pid1.power = 255;

digitalWrite(i1Pin, Pid1.flag);

digitalWrite(i2Pin, !Pid1.flag);

analogWrite(power1Pin, Pid1.power);

Pid2.flag = adjustValue2 > 512;

Pid2.power = abs(adjustValue2 - 512) / 2;

if(Pid2.power > 255) Pid2.power = 255;

digitalWrite(i3Pin, Pid2.flag);

digitalWrite(i4Pin, !Pid2.flag);

analogWrite(power2Pin, Pid2.power);

delay(32000);

return;

}

//Calculate power values

double v, error;

error = readValue1 - Pid1.target;

v = error - Pid1.preError;

Pid1.v = (Pid1.v * 6 + v) / 7;

Pid1.power = (int)error * Pid1.Kp + Pid1.v * Pid1.Kd;

Pid1.flag = Pid1.power > 0;

Pid1.power = abs(Pid1.power);

if(Pid1.power>255) Pid1.power = 255;

Pid1.preError = error;

error = readValue2 - Pid2.target;

v = error - Pid2.preError;

Pid2.v = (Pid2.v * 6 + v) / 7;

Pid2.power = (int)error * Pid2.Kp + Pid2.v * Pid2.Kd;

Pid2.flag = Pid2.power < 0;

Pid2.power = abs(Pid2.power);

if(Pid2.power>255) Pid2.power = 255;

Pid2.preError = error;

//Write PMW to control the floa

digitalWrite(i1Pin, Pid1.flag);

digitalWrite(i2Pin, !Pid1.flag);

analogWrite(power1Pin, Pid1.power);

digitalWrite(i3Pin, Pid2.flag);

digitalWrite(i4Pin, !Pid2.flag);

analogWrite(power2Pin, Pid2.power);

myLog[tick * 7 + 0] = tick;

myLog[tick * 7 + 1] = (int)Pid1.target;

myLog[tick * 7 + 2] = readValue1;

myLog[tick * 7 + 3] = Pid1.power;

myLog[tick * 7 + 4] = (int)Pid2.target;

myLog[tick * 7 + 5] = readValue2;

myLog[tick * 7 + 6] = Pid2.power;

/*

for(int i=0;i<8;i++)

{

digitalWrite(rotatePins[i] , 0);

digitalWrite(rotatePins[(i + 1) % 8] ,1);

delay(1);

}

digitalWrite(rotatePins[0] , 0);

*/

delay(delayMs);

}

我来回答

最后

以上就是等待奇异果为你收集整理的arduino串口绘图_有四组数据,但是为什么串口绘图器只画一个数据的图的全部内容,希望文章能够帮你解决arduino串口绘图_有四组数据,但是为什么串口绘图器只画一个数据的图所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(53)

评论列表共有 0 条评论

立即
投稿
返回
顶部