Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I get motor number in user pid ?
#1
I wrote "user_pid_ctrl".
For example,
double user_pid_ctrl(struct MotorData *Mptr)
{
test_buf = (int *)(pushm) + 1000 + Mtr_Index;
}

I need current motor number in user pid.
Reply
#2
Hi,

You can use this formula, for example:
Code:
#define Mtr0Base 0xBE2B8800
unsigned int *mtrnum = (unsigned int*)pushm + 2;
*mtrnum = ((unsigned int)Mptr - Mtr0Base)/2440;

Then the motor number will be in *mtrnum.

In general, the base address of each motor is 2440 * (MotorNumber) + Mtr0Base, where Mtr0Base is 0xBE2B8800.
Reply
#3
Thank you.
It operate well.
Reply
#4
For anyone who uses this method, it seems that the base motor address and the size of each motor has changed in later firmware versions. Here is a corrected version that should work on any firmware:

Code:
unsigned int motor = (unsigned int)Mptr;
unsigned int mbase = (unsigned int)&pshm->Motor[0];
unsigned int msize = (unsigned int)&pshm->Motor[1] - mbase;

unsigned int mnum = (motor - mbase) / msize; // motor number
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)