Raspberry PI wiringPi c ++ вызывает объект как прерывание - PullRequest
0 голосов
/ 09 марта 2020

Я довольно новичок в C ++, для робота c проекта, я создаю программу для управления несколькими двигателями, а также получить их скорость.

Для получения скорости, у меня есть «кодовое колесо», установленное на двигателях, которое подает сигнал 0/1 на вывод малины в зависимости от скорости двигателя.

Функция получает количество сегментов, полученных кодовым колесом (у меня разные ) и должен вернуть скорость двигателя. Активируется через прерывание с помощью wiringPiISR, чтобы избежать постоянной проверки всех параметров на oop.

Поскольку необходимо управлять несколькими двигателями, мне нужно повторять этот код столько раз, сколько имеется двигателей , Поэтому я создал файл класса с функцией в нем:

#include <iostream> //for Cout to display stuff
#include <chrono>   //library for counting time
#include <thread>   //for multithreading
#include <vector>
#include <wiringPi.h>   //Raspberry pi GPIO Library
#include "RPMCounter01.h"

RPMCounter::RPMCounter(){
    //int CodeWheelSegments = 0;
    int MNbSegments = 0, MNbSegmentsSeen = 0, MResult = 0;  //counter for the total number of segments
    //int MNbSegmentsSeen = 0;  //counter for the number of segments that have been seen
    //int MResult = 0;  //Result of the speed measurement the motort should turn at 220 rpm 
    std::chrono::duration<double> TotalResult;  //define TotalResult as nanoseconds in chrono library initialized at 0
    std::chrono::steady_clock::time_point BeginMeasurement; //chrono variable representing the beginning of the measurement of a motor speed
    double Freq = 0;    //frequency of the motor
}

void RPMCounter::FreqCounter(int CodeWheelSegments){
    using namespace std::chrono;

    duration<double> InstaResult = steady_clock::now() - BeginMeasurement;  //result of the time needed between 2 segments
    MNbSegments +=1;    //increasing the segment counter
    BeginMeasurement = steady_clock::now(); //start of a new cycle
    //std::cout << "BeginMeasurement = " << BeginMeasurement << '\n';
    if (InstaResult < milliseconds{100}){   //counting the time of impulsions if it's not bugged
        TotalResult = TotalResult + InstaResult;
        MNbSegmentsSeen += 1;
    }
    if (MNbSegments >= CodeWheelSegments){  //when the wheel did one turn
        //std::cout << "TotalResult = " << TotalResult.count() << '\n';
        Freq=TotalResult.count();   
        Freq = 60/((Freq/MNbSegmentsSeen)*CodeWheelSegments);   //calculating the frequency of the motor = 1/(Total time for all seen segments / Nb of segments see) * nb of segments
        std::cout << "Frequency = " << Freq << " RPM" << '\n';      //DIsplays the frequency of the motor
        //return Freq;
        MNbSegments = 0;            //reset all the parameters
        MNbSegmentsSeen = 0;
        TotalResult = 0s;
        //BeginMeasurement = steady_clock::now();
    }
}

файл заголовка

#ifndef DEF_RPMCounter
#define DEF_RPMCounter

class RPMCounter{
    public:
        RPMCounter();   //Constructeur
        void FreqCounter(int CodeWheelSegments);
    private:
        std::chrono::duration<double> TotalResult;  //define TotalResult as nanoseconds in chrono library initialized at 0
        std::chrono::steady_clock::time_point BeginMeasurement; //chrono variable representing the beginning of the measurement of a motor speed
        int CodeWheelSegments;
        int MNbSegments;    //counter for the total number of segments
        int MNbSegmentsSeen;    //counter for the number of segments that have been seen
        int MResult;    //Result of the speed measurement the motort should turn at 220 rpm 
        double Freq;    //frequency of the motor
};
#endif

Теоретически это должно работать.

Я звоню через эти строки:

//int wiringPiISR (int pin, int edgeType,  void (*function)(void)) ;
    RPMCounter RPMPouet;    //create an object of type RPMCounter
    wiringPiISR (Motor0In, INT_EDGE_RISING, RPMPouet.FreqCounter(36)); //create the interruption on the GPIO input nb "Motor0In" in case of rising edge for counting RPM

, что возвращает ошибку:

RobotControl03.cpp:133:69: error: invalid use of void expression
     wiringPiISR (Motor0In, INT_EDGE_RISING, RPMPouet.FreqCounter(36)); //create the interruption on the GPIO input nb "Motor0In" in case of rising edge for counting RPM

Что я делаю неправильно в этом вызове функции?

Я пробовал несколько разных способов, но безуспешно, и документация по этому поводу wiringPiISR совершенно не существует ...

Заранее спасибо!

...