arduinoで開発をしているのですが、
error
1ballSensor:53:17: error: variable or field 'sendVector' declared void 2 void sendVector(vectorRT_t vectorRTa, vectorXY_t vectorXYa){ 3 ^ 4ballSensor:53:17: error: 'vectorRT_t' was not declared in this scope 5ballSensor:53:39: error: 'vectorXY_t' was not declared in this scope 6 void sendVector(vectorRT_t vectorRTa, vectorXY_t vectorXYa){ 7 ^ 8ballSensor:74:39: error: 'ballCtrl' was not declared in this scope 9 void printPulseWidth(float pulseWidth[ballCtrl.numberOfBallSensors]){ 10 ^ 11exit status 1 12variable or field 'sendVector' declared void
とエラーが出てしまいます。
どなたか解決法を教えていただけるとありがたいです。
code
arduino
1//in ballSensor.ino 2#include "BallSensorCtrl.hpp" 3 4constexpr unsigned long baud = 115200; 5BallSensorCtrl ballCtrl; 6 7void setup(){ 8 Serial.begin(baud); 9} 10float pulseWidth[ballCtrl.numberOfBallSensors] = {}; 11int i = 0; 12unsigned long long previoustTime = millis(); 13//vectorRT_t previousVectorRT = {}; 14//vectorXY_t previousVectorXY = {}; 15 16void loop(){ 17 float currentPulseWidth[ballCtrl.numberOfBallSensors] = {}; 18 ballCtrl.getPulseWidth(currentPulseWidth); 19 20 static float rate = 0.05; 21 for(int i = 0;i<12;i++){ 22 pulseWidth[i] = currentPulseWidth[i] * rate + pulseWidth[i] * (1 - rate); 23 } 24 vectorXY_t vectorXY = ballCtrl.CaluculateVectorXY(pulseWidth); 25 vectorRT_t vectorRT = ballCtrl.CaluculateVectorRT(pulseWidth); 26 27 //10msごと 28 if(millis() - previoustTime > 10){ 29 //sendVectorRTIntBySerial(vectorRTInt); 30 Serial.print("radius : "); 31 Serial.print(vectorRT.radius); 32 Serial.print(" theta : "); 33 Serial.print(vectorRT.theta); 34 //printVectorRTIntBySerial(vectorRTInt, deltaVectorXYInt); 35 //printPulseWidth(pulseWidth); 36 previoustTime = millis(); 37 //previousVectorRT = vectorRT; 38 //previousVectorXY = vectorXY; 39 } 40 //受け取った時 41 if (Serial.available()){ 42 char header = Serial.read(); 43 if(header == 'b'){ 44 //int a = sendVector(vectorXY,vectorRT); 45 //printVectorRTIntBySerial(vectorRTInt, deltaVectorXYInt); 46 //printPulseWidth(pulseWidth); 47 //previousVectorRT = vectorRT; 48 //previousVectorXY = vectorXY; 49 } 50 } 51 //printPulseWidth(pulseWidth); 52} 53 54void sendVector(vectorRT_t vectorRTa, vectorXY_t vectorXYa){ 55 float x = vectorXYa.x; 56 float y = vectorXYa.y; 57 58 float radius = vectorRTa.radius; 59 float theta = vectorRTa.theta; 60 61 /*Serial.write('B'); 62 Serial.write(lowByte(radius)); 63 Serial.write(highByte(radius)); 64 Serial.write(lowByte(theta)); 65 Serial.write(highByte(theta)); 66 67 Serial.write(lowByte(x)); 68 Serial.write(highByte(x)); 69 Serial.write(lowByte(y)); 70 Serial.write(highByte(y));*/ 71 72 //return; 73} 74 75void printPulseWidth(float pulseWidth[ballCtrl.numberOfBallSensors]){ 76 Serial.print(" 0 : "); 77 Serial.print(pulseWidth[0]); 78 Serial.print(" 1 : "); 79 Serial.print(pulseWidth[1]); 80 Serial.print(" 2 : "); 81 Serial.print(pulseWidth[2]); 82 Serial.print(" 3 : "); 83 Serial.print(pulseWidth[3]); 84 Serial.print(" 4 : "); 85 Serial.print(pulseWidth[4]); 86 Serial.print(" 5 : "); 87 Serial.print(pulseWidth[5]); 88 Serial.print(" 6 : "); 89 Serial.print(pulseWidth[6]); 90 Serial.print(" 7 : "); 91 Serial.print(pulseWidth[7]); 92 Serial.print(" 8 : "); 93 Serial.print(pulseWidth[8]); 94 Serial.print(" 9 : "); 95 Serial.print(pulseWidth[9]); 96 Serial.print(" 10 : "); 97 Serial.print(pulseWidth[10]); 98 Serial.print(" 11 : "); 99 Serial.print(pulseWidth[11]); 100 Serial.println(); 101} 102
//in BallSensorCtrl.cpp #include <digitalWriteFast.h> #include "BallSensorCtrl.hpp" void BallSensorCtrl::setupSensors(){ pinMode(BallSensorPins[0],INPUT); pinMode(BallSensorPins[1],INPUT); pinMode(BallSensorPins[2],INPUT); pinMode(BallSensorPins[3],INPUT); pinMode(BallSensorPins[4],INPUT); pinMode(BallSensorPins[5],INPUT); pinMode(BallSensorPins[6],INPUT); pinMode(BallSensorPins[7],INPUT); pinMode(BallSensorPins[8],INPUT); pinMode(BallSensorPins[9],INPUT); pinMode(BallSensorPins[10],INPUT); pinMode(BallSensorPins[11],INPUT); } void BallSensorCtrl::getPulseWidth(float pulseWidth[numberOfBallSensors]){ uint16_t timeLimit = IRBallWaveformModeA; unsigned long startTime_us = micros(); do{ //全センサを同時読み for (int i = 0; i < numberOfBallSensors/2; i++){ if (digitalReadFast(BallSensorPins[i]) == false) { pulseWidth[i] += deltaPulseWidth; } } } while ((micros() - startTime_us) < timeLimit); startTime_us = micros(); do{ //全センサを同時読み for (int i = numberOfBallSensors/2; i < numberOfBallSensors; i++){ if (digitalReadFast(BallSensorPins[i]) == false) { pulseWidth[i] += deltaPulseWidth; } } } while ((micros() - startTime_us) < timeLimit); return; } vectorXY_t BallSensorCtrl::CaluculateVectorXY(float pulseWidth[numberOfBallSensors]){ vectorXY_t result; result.x = 0; result.y = 0; for(int i = 0;i<numberOfBallSensors;i++){ result.x += pulseWidth[i] * UnitVectorX[i]; result.y += pulseWidth[i] * UnitVectorY[i]; } /*if(result.x != 0 || result.y != 0){ float squared = result.x * result.x + result.y * result.y; float root = sqrt(squared); result.x /= root; result.y /= root; }*/ return result; } vectorRT_t BallSensorCtrl::CaluculateVectorRT(float pulseWidth[numberOfBallSensors]){ vectorRT_t returnValue; vectorXY_t result; result.x = 0; result.y = 0; float pulseWidthSum = 0; for(int i = 0;i<numberOfBallSensors;i++){ result.x += pulseWidth[i] * UnitVectorX[i]; result.y += pulseWidth[i] * UnitVectorY[i]; pulseWidthSum += pulseWidth[i]; } float sqrtRadius = sqrt(pulseWidthSum); float cube = pulseWidthSum * sqrtRadius; float rate; if (cube > 0.0001) rate = 1 / cube * 500; else rate = 0; result.x *= rate; result.y *= rate; returnValue.theta = atan2(result.x,result.y); returnValue.radius = result.x * result.x + result.y * result.y; returnValue.radius /= 100; return returnValue; }
//in BallSensorCtrl.hpp #ifndef BallCtrl_h #define BallCtrl_h typedef struct{ float radius; float theta; } vectorRT_t; typedef struct{ float x; float y; } vectorXY_t; class BallSensorCtrl{ public: static constexpr int numberOfBallSensors = 12; void setupSensors(); void getPulseWidth(float pulseWidth[numberOfBallSensors]); vectorXY_t CaluculateVectorXY(float pulseWidth[numberOfBallSensors]); vectorRT_t CaluculateVectorRT(float pulseWidth[numberOfBallSensors]); //センサーのピン番号 今 //uint8_t BallSensorPins[numberOfBallSensors] = {9, 8, 7, 6, 5, 4, 3, 2, A2, A1, A0, 10}; //昔 uint8_t BallSensorPins[numberOfBallSensors] = {A2, A1, 9, A0, 8, 5, 4, 3, 2, A5, A4, A3}; private: static constexpr uint16_t IRBallWaveformModeA = 833; static constexpr float deltaPulseWidth = 1.0; float UnitVectorX[numberOfBallSensors] = {0.000, 0.500, 0.866, 1.000, 0.866, 0.500, 0.000, -0.500, -0.866, -1.000, -0.866, -0.500}; float UnitVectorY[numberOfBallSensors] = {1.000, 0.866, 0.500, 0.000, -0.500, -0.866, -1.000, -0.866, -0.500, 0.000, 0.500, 0.866}; }; #endif
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。