Set Paramters from class to another class

Dear

could any one help me how to set in Main Program the the values of Parameters (Wheel diameter , Trackwidth , TicksPerRevolution) where they are located in RobotParams Class , I think they related with void RequestInitialization() function which is in Main Program , but I don’t know how to deal with that .

Main Program

#include "Arduino.h"
#include <RobotParams.h>
#include <TimeInfo.h>
#include <OdometricLocalizer.h>
#include <Messenger.h>
#include <digitalWriteFast.h>  


// container for robot params wheel diameter [m], trackwidth [m], ticks per revolution
RobotParams _RobotParams = RobotParams();
TimeInfo _TimeInfo = TimeInfo();


// Quadrature encoders
// Left encoder
#define c_LeftEncoderInterrupt 4
#define c_LeftEncoderPinA 19
#define c_LeftEncoderPinB 25
#define LeftEncoderIsReversed
volatile bool _LeftEncoderBSet;
volatile long _LeftEncoderTicks = 0;

// Right encoder
#define c_RightEncoderInterrupt 5
#define c_RightEncoderPinA 18
#define c_RightEncoderPinB 24
volatile bool _RightEncoderBSet;
volatile long _RightEncoderTicks = 0;

OdometricLocalizer _OdometricLocalizer(&_RobotParams, &_TimeInfo);


// Instantiate Messenger object with the message function and the default separator (the space character)
Messenger _Messenger = Messenger();

bool _IsInitialized = false;

void setup()
{
  Serial.begin(115200);

  SetupEncoders();

  _Messenger.attach(OnMssageCompleted);


  delay(100);
  _TimeInfo.Update();
}

could any one help me how to set in Main Program the the values of Parameters (Wheel diameter , Trackwidth , TicksPerRevolution) where they are located in RobotParams Class

The same way that it is done here:

void InitializeDriveGeometry()
{
  float wheelDiameter = GetFloatFromBaseAndExponent(_Messenger.readInt(), _Messenger.readInt());
  float trackWidth = GetFloatFromBaseAndExponent(_Messenger.readInt(), _Messenger.readInt());
  int countsPerRevolution = _Messenger.readInt();
  
  _RobotParams.Initialize(wheelDiameter, trackWidth, countsPerRevolution);
}

PaulS:

could any one help me how to set in Main Program the the values of Parameters (Wheel diameter , Trackwidth , TicksPerRevolution) where they are located in RobotParams Class

The same way that it is done here:

void InitializeDriveGeometry()
{
  float wheelDiameter = GetFloatFromBaseAndExponent(_Messenger.readInt(), _Messenger.readInt());
  float trackWidth = GetFloatFromBaseAndExponent(_Messenger.readInt(), _Messenger.readInt());
  int countsPerRevolution = _Messenger.readInt();
  
  _RobotParams.Initialize(wheelDiameter, trackWidth, countsPerRevolution);
}

thanks PaulS

but what i understand from above is that after I run the main program , a indicator should appear telling the user to enter the three values of (wheelDiameter, trackWidth, countsPerRevolution) but ,actually when i run the main program no thing such that happen .

but what i understand from above is that after I run the main program , a indicator should appear telling the user to enter the three values of (wheelDiameter, trackWidth, countsPerRevolution) but ,actually when i run the main program no thing such that happen .

An indicator? Do you mean a prompt?

Appear where? And where are you looking for it?

Have you tried adding other Serial.print() statements?

PaulS:

but what i understand from above is that after I run the main program , a indicator should appear telling the user to enter the three values of (wheelDiameter, trackWidth, countsPerRevolution) but ,actually when i run the main program no thing such that happen .

An indicator? Do you mean a prompt?

Appear where? And where are you looking for it?

Have you tried adding other Serial.print() statements?

Yes , I mean the prompt .

actually , from my little bit knowledge in arduino programming , I thought that code below will show a prompt telling me to to enter the three values , is that right , and if it isn't , so what the benefit of void InitializeDriveGeometry() and Messenger.readInt() .

// set robot params wheel diameter [m], trackwidth [m], ticks per revolution
void InitializeDriveGeometry()
{
  float wheelDiameter = GetFloatFromBaseAndExponent(_Messenger.readInt(), _Messenger.readInt());
  float trackWidth = GetFloatFromBaseAndExponent(_Messenger.readInt(), _Messenger.readInt());
  int countsPerRevolution = _Messenger.readInt();
  
  _RobotParams.Initialize(wheelDiameter, trackWidth, countsPerRevolution);
}

actually , from my little bit knowledge in arduino programming , I thought that code below will show a prompt telling me to to enter the three values , is that right

No, that code won't.

This code should:

    if (!_RobotParams.IsInitialized)
    {
      _IsInitialized = false;

      Serial.print("InitializeDriveGeometry"); // requesting initialization of the parameters of the differential drive needed for odometry calculations
      Serial.print("\n");
    }

However, I don't like this code:

RobotParams _RobotParams = RobotParams();
TimeInfo _TimeInfo = TimeInfo();

You should never call the constructor directly.

RobotParams _RobotParams;
TimeInfo _TimeInfo;

This will invoke, indirectly, the constructor, which is the way it should be invoked.

so what the benefit of void InitializeDriveGeometry() and Messenger.readInt() .

The function is there to be called when there is sufficient data to initialize the instance, and readInt() is used to extract a value from the serial data that was received (assuming that there was some).

You need to add some more Serial.print() statements to the code, to see what it is actually doing. Start with adding: Serial.println("PaulS is handsome"); to setup.

Make sure that the message prints exactly once.

thanks a lot Pual

actually I am trying to determine the Odometry of my Rover robot by helping of two encoders per wheel , while I am googling I found the codes (in the first post) which they really what i need but with a little modification in somewhere , the final main program became as code below , but when I run that code (with moving the wheel manually )and I expected to show me the values of x , y , heading on serial monitor but the output was just as below , so what is the problem ?

Odometry
InitializeDriveGeometry
InitializeDriveGeometry
InitializeDriveGeometry
InitializeDriveGeometry
InitializeDriveGeometry
InitializeDriveGeometry
InitializeDriveGeometry
.
.
.
.
.
.
.
.
.
.

hint : the other related classes in the attachments

Main Program

#include "Arduino.h"
#include <RobotParams.h>
#include <TimeInfo.h>
#include <OdometricLocalizer.h>
#include <Messenger.h>
#include <digitalWriteFast.h>  


// container for robot params wheel diameter [m], trackwidth [m], ticks per revolution
RobotParams _RobotParams = RobotParams();
TimeInfo _TimeInfo = TimeInfo();

// Quadrature encoders
// Left encoder
#define c_LeftEncoderInterrupt 0
#define c_LeftEncoderPinA 2
#define c_LeftEncoderPinB 4
#define LeftEncoderIsReversed
volatile bool _LeftEncoderBSet;
volatile long _LeftEncoderTicks = 0;

#define c_UpdateInterval 20 
 
// Right encoder
#define c_RightEncoderInterrupt 1
#define c_RightEncoderPinA 3
#define c_RightEncoderPinB 5
volatile bool _RightEncoderBSet;
volatile long _RightEncoderTicks = 0;
 





// Instantiate Messenger object with the message function and the default separator (the space character)
Messenger _Messenger = Messenger();

bool _IsInitialized = false;

void setup()
{
  Serial.begin(9600);

  SetupEncoders();



  delay(100);
  _TimeInfo.Update();
}

void SetupEncoders()
{
  // Quadrature encoders
  // Left encoder
  pinMode(c_LeftEncoderPinA, INPUT);      // sets pin A as input
  digitalWrite(c_LeftEncoderPinA, LOW);  // turn on pullup resistors
  pinMode(c_LeftEncoderPinB, INPUT);      // sets pin B as input
  digitalWrite(c_LeftEncoderPinB, LOW);  // turn on pullup resistors
  attachInterrupt(c_LeftEncoderInterrupt, HandleLeftMotorInterruptA, RISING);
  
  // Right encoder
  pinMode(c_RightEncoderPinA, INPUT);      // sets pin A as input
  digitalWrite(c_RightEncoderPinA, LOW);  // turn on pullup resistors
  pinMode(c_RightEncoderPinB, INPUT);      // sets pin B as input
  digitalWrite(c_RightEncoderPinB, LOW);  // turn on pullup resistors
  attachInterrupt(c_RightEncoderInterrupt, HandleRightMotorInterruptA, RISING); 
}

but when I run that code (with moving the wheel manually )and I expected to show me the values of x , y , heading on serial monitor but the output was just as below , so what is the problem ?

The "problem" is that you are being prompted to enter three values, but you appear to be ignoring that prompt.

Frankly, I think that the code you are using is ridiculous. Skip the messenger crap. Skip the prompt. Skip the serial input. Just hard-code the values. After all, you're not going to be changing tires mid-run are you?

PaulS:

but when I run that code (with moving the wheel manually )and I expected to show me the values of x , y , heading on serial monitor but the output was just as below , so what is the problem ?

The "problem" is that you are being prompted to enter three values, but you appear to be ignoring that prompt.

Frankly, I think that the code you are using is ridiculous. Skip the messenger crap. Skip the prompt. Skip the serial input. Just hard-code the values. After all, you're not going to be changing tires mid-run are you?

thanks PaulS , actually after run I enter the three values but not thing happen also the word " InitializeDriveGeometry " still appear on serial monitor repeatedly and not stop .

actually I tried to skip unnecessary codes but errors and bugs appear .

Could you tell me what the ridiculous thing in the code ? What do you mean by "you're not going to be changing tires mid-run are you?" ?

What do you mean by "you're not going to be changing tires mid-run are you?" ?

The values that you are supposed to enter are wheel diameter, track width, and counts per revolution. For YOUR robot, are these values ever going to change? If not, hard-code them, instead of having to enter them each time.

If they might, weigh the benefits of being able to enter the values every time versus the cost of having to upload new code to change the hardcoded values.

For your level of experience, I don't think that the benefits of being able to change the values without changing the code are worth the complexity of the code.

PaulS:

What do you mean by "you're not going to be changing tires mid-run are you?" ?

The values that you are supposed to enter are wheel diameter, track width, and counts per revolution. For YOUR robot, are these values ever going to change? If not, hard-code them, instead of having to enter them each time.

If they might, weigh the benefits of being able to enter the values every time versus the cost of having to upload new code to change the hardcoded values.

For your level of experience, I don't think that the benefits of being able to change the values without changing the code are worth the complexity of the code.

Thanks PaulS ,

Yes , these values are constants and never going to change every time .

I have solved the problem and the code working very good , thank you PaulS for your support .