unexpected error message, arduino SharpIR - c++

I am trying to use a GPY2Y0A21Y IRsensor, but I am having trouble making the code work. I downloaded SharpIR but got a bug when using one of its functions,
#include <SharpIR.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
SharpIR sharp("A1", 25, 93, 1080);
}
void loop() {
// put your main code here, to run repeatedly:
}
and this is the error message
/var/folders/_z/t_qth0vd0xj6fxvyp_k5nvc00000gn/T/arduino_modified_sketch_475607/sketch_jan17a.ino: In function 'void setup()':
sketch_jan17a:7: error: no matching function for call to 'SharpIR::SharpIR(const char [3], int, int, int)'
SharpIR sharp("A1", 25, 93, 1080);
^
/var/folders/_z/t_qth0vd0xj6fxvyp_k5nvc00000gn/T/arduino_modified_sketch_475607/sketch_jan17a.ino:7:33: note: candidates are:
In file included from /var/folders/_z/t_qth0vd0xj6fxvyp_k5nvc00000gn/T/arduino_modified_sketch_475607/sketch_jan17a.ino:1:0:
/Users/jeroenturkstra/Documents/Arduino/libraries/SharpIR/src/SharpIR.h:29:5: note: SharpIR::SharpIR(uint8_t, uint8_t)
SharpIR(uint8_t _sensorType, uint8_t _sensorPin);
^
/Users/jeroenturkstra/Documents/Arduino/libraries/SharpIR/src/SharpIR.h:29:5: note: candidate expects 2 arguments, 4 provided
/Users/jeroenturkstra/Documents/Arduino/libraries/SharpIR/src/SharpIR.h:25:7: note: constexpr SharpIR::SharpIR(const SharpIR&)
class SharpIR
^
/Users/jeroenturkstra/Documents/Arduino/libraries/SharpIR/src/SharpIR.h:25:7: note: candidate expects 1 argument, 4 provided
/Users/jeroenturkstra/Documents/Arduino/libraries/SharpIR/src/SharpIR.h:25:7: note: constexpr SharpIR::SharpIR(SharpIR&&)
/Users/jeroenturkstra/Documents/Arduino/libraries/SharpIR/src/SharpIR.h:25:7: note: candidate expects 1 argument, 4 provided
exit status 1
no matching function for call to 'SharpIR::SharpIR(const char [3], int, int, int)'
I am not super familiar with libraries and such so I have no clue what is wrong with this code. All I got is that the function doesn't exist. I did download SharpIR btw. If anyone can help, it would be appreciated (had the example code from this site https://playground.arduino.cc/Main/SharpIR)

The error seems to be legit, looking at the SharpIR declaration. Maybe the guide that you are following is deprecated and not compatible with your installed library?
class SharpIR
{
public:
SharpIR (int irPin, long sensorModel);
int distance();
private:
void sort(int a[], int size);
int _irPin;
long _model;
};
The object initialization requires only a pin number and a long that identifies the sensor model. BUT looking at the error in your question it seems that the declarations is implemented with the sensor identification number as first argument and the pin number as second. I think you should really open up the source in your local installation and check it out. You can print it in terminal with:
cat /Users/jeroenturkstra/Documents/Arduino/libraries/SharpIR/src/SharpIR.h
(I cannot open Dropbox link right now...)

Related

Compile errors in Tensorflow Lite Micro framework when trying to integrate Tensorflow Lite Micro to my ESP32 Arduino project

Hi stackoverflow community,
I am trying to get a project leveraging Tensorflow Lite Micro to run on my ESP32 using PlatformIO and the Arduino framework (not ESP-IDF). Basically, I followed the guide in this medium post https://towardsdatascience.com/tensorflow-meet-the-esp32-3ac36d7f32c7 and then included everything in my already existing ESP32 project.
My project was compiling fine prior to the integration of Tensorflow Lite Micro but since integrating it, I am getting the following compile errors which seem to be related to the Tensorflow framework itself. When I uncomment everything related to Tensorflow, it compiles fine. But just when only including the following header files, it breaks:
#include "tensorflow/lite/micro/kernels/micro_ops.h"
#include "tensorflow/lite/micro/micro_error_reporter.h"
#include "tensorflow/lite/micro/micro_interpreter.h"
#include "tensorflow/lite/micro/micro_mutable_op_resolver.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/version.h"
Does someone know where these errors come from and what I can do to solve those?
Here is the error trace:
In file included from /Users/XXX/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiClient.h:24:0,
from /Users/XXX/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFi.h:37,
from src/main.cpp:3:
/Users/XXX/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:64:17: error: expected identifier before numeric constant
#define DEFAULT 1
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:31:5: note: in expansion of macro 'DEFAULT'
DEFAULT = 1,
^
/Users/XXX/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:64:17: error: expected '}' before numeric constant
#define DEFAULT 1
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:31:5: note: in expansion of macro 'DEFAULT'
DEFAULT = 1,
^
/Users/XXX/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:64:17: error: expected unqualified-id before numeric constant
#define DEFAULT 1
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:31:5: note: in expansion of macro 'DEFAULT'
DEFAULT = 1,
^
In file included from lib/tfmicro/tensorflow/lite/micro/micro_interpreter.h:24:0,
from src/main.cpp:12:
lib/tfmicro/tensorflow/lite/core/api/profiler.h:51:21: error: declaration of '~tflite::Profiler' as non-member
virtual ~Profiler() {}
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:61:48: error: 'EventType' has not been declared
virtual uint32_t BeginEvent(const char* tag, EventType event_type,
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:63:54: error: 'virtual' outside class declaration
int64_t event_metadata2) = 0;
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:63:58: error: function 'uint32_t tflite::BeginEvent(const char*, int, int64_t, int64_t)' is initialized like a variable
int64_t event_metadata2) = 0;
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:65:40: error: 'EventType' has not been declared
uint32_t BeginEvent(const char* tag, EventType event_type,
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:74:48: error: 'virtual' outside class declaration
int64_t event_metadata2) {}
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:76:46: error: 'virtual' outside class declaration
virtual void EndEvent(uint32_t event_handle) = 0;
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:76:50: error: function 'void tflite::EndEvent(uint32_t)' is initialized like a variable
virtual void EndEvent(uint32_t event_handle) = 0;
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:85:34: error: 'EventType' has not been declared
void AddEvent(const char* tag, EventType event_type, uint64_t start,
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h: In function 'void tflite::AddEvent(const char*, int, uint64_t, uint64_t, int64_t)':
lib/tfmicro/tensorflow/lite/core/api/profiler.h:88:35: error: too many arguments to function 'void tflite::AddEvent(const char*, int, uint64_t, uint64_t, int64_t)'
/*event_metadata2*/ 0);
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:85:8: note: declared here
void AddEvent(const char* tag, EventType event_type, uint64_t start,
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h: At global scope:
lib/tfmicro/tensorflow/lite/core/api/profiler.h:91:42: error: 'EventType' has not been declared
virtual void AddEvent(const char* tag, EventType event_type, uint64_t start,
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:93:48: error: 'virtual' outside class declaration
int64_t event_metadata2) {}
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:95:2: error: expected unqualified-id before 'protected'
protected:
^
lib/tfmicro/tensorflow/lite/core/api/profiler.h:105:25: error: expected ')' before '*' token
ScopedProfile(Profiler* profiler, const char* tag,
^
src/main.cpp:202:1: error: expected '}' at end of input
}
^
src/main.cpp:202:1: error: expected unqualified-id at end of input
*** [.pio/build/esp32cam/src/main.cpp.o] Error 1
Today I faced a similar problem. I solved it by using TensorFlowLite_ESP32 library instead of Arduino_TensorFlowLite. You need to download this library and add the line #include <TensorFlowLite_ESP32.h>. I hope this helps you too
I resolved this for now by switching from the Arduino framework to the ESP-IDF framework. With this, it works like a charm.

Why is it possible to pass a void(*)(int x, int y) to attachInterrupt that expects void(*)()?

I've been inattentive and for some reason created a function that takes two arguments, and I passed it to attachInterrupt like so:
int state = 42;
void simplified_state_handler(){
state++;
}
void interrupt_func(int x, int y) {
simplified_state_handler();
}
attachInterrupt(digitalPinToInterrupt(10), interrupt_func, CHANGE);
The code got compiled with no complaints at all, and it even works. Now, a bit later, I really can't understand why. Reading and digging the attachInterrupt code didn't help. Please explain why can I pass such a function at all. I'm keeping the (now) useless simplified_state_handler in the example, maybe it is important.
The compiler settings of the AVR boards allow it.
It is only a warning: invalid conversion from 'void (*)(int, int)' to 'void (*)()' [-fpermissive].
On other Arduino platforms (SAMD, STM32, esp8266) it is an error.
The compiler settings in AVR platform were benevolent from the start and they can't change them suddenly. Many existing codes would not compile then.

ESP32: Compile errors when using IRAM_ATTR

I am sure I am doing something really stupid, but here goes..
I get a compile error when I use IRAM_ATTR for my ISR. I am compiling for ESP32.
Here is the definition of the ISR
void
IRAM_ATTR
detectsBlockOccupancy() {
....
ISR code..
...
}
And here is the first usage:
void setup() {
// Set Sensor pin as interrupt, assign interrupt function and set RISING mode
attachInterrupt(digitalPinToInterrupt(BDInterruptPin), detectsBlockOccupancy, RISING);
...
}
The error I get is as follows:
In function 'void setup()': Node0:226:90: error: invalid conversion
from 'int ()()' to 'void ()()' [-fpermissive]
attachInterrupt(digitalPinToInterrupt(BDInterruptPin), detectsBlockOccupancy, RISING);
^ In file included from
C:\Users\vibhas\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/esp32-hal.h:53:0,
from C:\Users\vibhas\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Arduino.h:35,
from sketch\Node0.ino.cpp:1: C:\Users\vibhas\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/esp32-hal-gpio.h:81:6:
note: initializing argument 2 of 'void attachInterrupt(uint8_t, void
()(), int)' void attachInterrupt(uint8_t pin, void ()(void), int
mode);
^
If I remove the IRAM_ATTR then it compiles fine. It seems to think that I am trying to pass a different type of function pointer.
What could I be doing wrong ?
Thanks
vibhas

Cannot convert string to char* for argument 1

I am having an issue with my C++ code for converting a string of numbers in base b to another base n. My error is as follows:
cannot convert ‘std::__cxx11::string {aka std::__cxx11::basic_string<char>}’ to ‘char*’ for argument ‘1’ to ‘int base_to_decimal(char*, int)’
I am using g++ to compile, and I have been for a while, so I thought at first I knew what the issue was. It says that the method base_to_decimal accepts two arguments: one of type char* and one of type int. So all I should have to do to fix my issue is change the char* argument to a string, right?
Well, I looked, and the code for the function in question is:
int base_to_decimal(std::string input_base, int base)
So this method SHOULD be expecting a string, but for some reason when I pass in a string, it gets angry at me.
If someone could help me figure this out, that would be fantastic. I am using g++ 7.3.0, and running all this on Linux Mint 19.1.
(EDIT)
Main Method
Functions
Table
You've written a custom declaration on line 46 of your main:
int base_to_decimal(char * input_base, int base)
But in the functions file where you've defined your function, you have:
int base_to_decimal(std::string input_base, int base)
This is why you should not write in-line declarations for external functions, but instead put the declarations in a header file. #include in the file where the function is later defined, ensures that the definition matches the declaration that the other files are expecting. And likewise, it enforces that all those other files are trying to use the function the way it's actually coded.

Template function call ambiguity error

I am not familiar with templates. I've just started learning it. Why I am getting errors in following program?
#include <iostream>
#include <string>
using std::cout;
using std::string;
template<class C>
C min(C a,C b) {
return a<b?a:b;
}
int main()
{
string a="first string";
string b="second string";
cout<<"minimum string is: "<<min(a,b)<<'\n';
int c=3,d=5;
cout<<"minimum number is: "<<min(c,d)<<'\n';
double e{3.3},f{6.6};
cout<<"minimum number is: "<<min(e,f)<<'\n';
char g{'a'},h{'b'};
cout<<"minimum number is: "<<min(g,h)<<'\n';
return 0;
}
Errors:
13 [Error] call of overloaded 'min(std::string&, std::string&)' is ambiguous
6 [Note] C min(C, C) [with C = std::basic_string<char>]
Please help me.
There are a two things going on here.
Your first problem is that you only included part of the error message. Here is a link to the code being complied in gcc and clang, and one of the resulting error messages (in full):
main.cpp:13:34: error: call to 'min' is ambiguous
cout<<"minimum string is: "<<min(a,b)<<'\n';
^~~
/usr/include/c++/v1/algorithm:2579:1: note: candidate function [with _Tp = std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >]
min(const _Tp& __a, const _Tp& __b)
^
main.cpp:6:3: note: candidate function [with C = std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >]
C min(C a,C b) {
^
there are two candidates. One at main.cpp:6:3 (line 6, character 3) and one at algorithm:2579:1 (line 2579, character 1).
One of them you wrote, and one of them in #include <algorithm>.
One of your header files included <algorithm> without you asking for it. The standard headers are allowed to do this, as annoying as it is sometimes.
In <algorithm> there is a std::min function template. As std::string is an instance of a template class in namespace std, the function template std::min is found via a process called "argument dependent lookup" or "Koenig lookup". (function overload candidates are searched for locally, and also in the namespaces of the arguments to the function, and in the namespaces of the template arguments to the arguments to the function, and in the namespaces of the things pointed to by the arguments of the function, etc.)
Your local function min is also found, as it is in the same namespace as the body of main.
Both are equally good matches, and the compiler cannot decide which one you want to call. So it generates an error telling you this.
Both gcc and clang do error: then a sequence of note:s. Usually all of the note:s after an error are important to understanding the error.
To fix this, try calling ::min (fully qualifying the call), or renaming the function to something else, or make your version a better match than std::min (tricky, but doable in some cases), or calling (min)(a,b). The last blocks ADL/Koenig lookup, and also blocks macro expansion (for example, if some OS has injected #define min macros into their system headers) (via # 0x499602D2).
You're running into a name collision with std::min. It is likely included in one of the other standard libary headers that you included, either <iostream> or <string>, my guess is probably the latter. The quick fix is to rename your function. For example, renaming it to mymin works fine. Demo