Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reassigning motor feedback pEnc in C code
#1
I need to change a motor's pEnc in the rticplc.

This caused a HW watchdog so I guess is incorrect (C address rather than pmac address) (the numbers are actually variables but I have simplified here):

Code:
//pshm->Motor[7].pEnc = &pshm->EncTable[7];
//pshm->Motor[7].pEnc2 = &pshm->EncTable[7];

This didn't watchdog but I haven't checked is actually functioning:

Code:
char buffer[512];
sprintf(buffer, "Motor[%d].pEnc = EncTable[%d].a", 7, 7);
Command(buffer);
sprintf(buffer, "Motor[%d].pEnc2 = EncTable[%d].a", 7, 7);
Command(buffer);

I want to know

1) Is this the correct method?
2) Is it robust?
3) Does it use ASCII comms (i.e. will the action be delayed)?
4) Is there an alternative?

Thanks
Reply
#2
Hi,

I do not recommend using Command() ever in any foreground task unless absolutely necessary as it does require use of the PMAC parser.

You're right that using pshm->EncTable[7] in C causes problems. I am not sure why without looking at the firmware code.

However, an alternate approach would be to calculate the EncTable[n].a value with the following function:

Code:
EncData* GetEncTableAddress(unsigned int EncTableIndex)
{
    return (EncData*)(3189981184 + 56*EncTableIndex);

}

Then, you can use it like this:

Code:
unsigned int EncTableIndex=7;
pshm->Motor[1].pEnc = GetEncTableAddress(EncTableIndex);
pshm->Motor[1].pEnc2 = GetEncTableAddress(EncTableIndex);

You can just set EncTableIndex to whatever and it will change the addresses for you. Please let me know if that works for you (it works on my system).

You could also use a big hash table with predefined EncTable addresses if you'd prefer not computing the address each time. Below is a table of the defines you could use (note that the addresses are in decimal, not hexadecimal):

Code:
#define EncTable0Address 3189981184
#define EncTable1Address 3189981240
#define EncTable2Address 3189981296
#define EncTable3Address 3189981352
#define EncTable4Address 3189981408
#define EncTable5Address 3189981464
#define EncTable6Address 3189981520
#define EncTable7Address 3189981576
#define EncTable8Address 3189981632
#define EncTable9Address 3189981688
#define EncTable10Address 3189981744
#define EncTable11Address 3189981800
#define EncTable12Address 3189981856
#define EncTable13Address 3189981912
#define EncTable14Address 3189981968
#define EncTable15Address 3189982024
#define EncTable16Address 3189982080
#define EncTable17Address 3189982136
#define EncTable18Address 3189982192
#define EncTable19Address 3189982248
#define EncTable20Address 3189982304
#define EncTable21Address 3189982360
#define EncTable22Address 3189982416
#define EncTable23Address 3189982472
#define EncTable24Address 3189982528
#define EncTable25Address 3189982584
#define EncTable26Address 3189982640
#define EncTable27Address 3189982696
#define EncTable28Address 3189982752
#define EncTable29Address 3189982808
#define EncTable30Address 3189982864
#define EncTable31Address 3189982920
#define EncTable32Address 3189982976
#define EncTable33Address 3189983032
#define EncTable34Address 3189983088
#define EncTable35Address 3189983144
#define EncTable36Address 3189983200
#define EncTable37Address 3189983256
#define EncTable38Address 3189983312
#define EncTable39Address 3189983368
#define EncTable40Address 3189983424
#define EncTable41Address 3189983480
#define EncTable42Address 3189983536
#define EncTable43Address 3189983592
#define EncTable44Address 3189983648
#define EncTable45Address 3189983704
#define EncTable46Address 3189983760
#define EncTable47Address 3189983816
#define EncTable48Address 3189983872
#define EncTable49Address 3189983928
#define EncTable50Address 3189983984
#define EncTable51Address 3189984040
#define EncTable52Address 3189984096
#define EncTable53Address 3189984152
#define EncTable54Address 3189984208
#define EncTable55Address 3189984264
#define EncTable56Address 3189984320
#define EncTable57Address 3189984376
#define EncTable58Address 3189984432
#define EncTable59Address 3189984488
#define EncTable60Address 3189984544
#define EncTable61Address 3189984600
#define EncTable62Address 3189984656
#define EncTable63Address 3189984712
#define EncTable64Address 3189984768
#define EncTable65Address 3189984824
#define EncTable66Address 3189984880
#define EncTable67Address 3189984936
#define EncTable68Address 3189984992
#define EncTable69Address 3189985048
#define EncTable70Address 3189985104
#define EncTable71Address 3189985160
#define EncTable72Address 3189985216
#define EncTable73Address 3189985272
#define EncTable74Address 3189985328
#define EncTable75Address 3189985384
#define EncTable76Address 3189985440
#define EncTable77Address 3189985496
#define EncTable78Address 3189985552
#define EncTable79Address 3189985608
#define EncTable80Address 3189985664
#define EncTable81Address 3189985720
#define EncTable82Address 3189985776
#define EncTable83Address 3189985832
#define EncTable84Address 3189985888
#define EncTable85Address 3189985944
#define EncTable86Address 3189986000
#define EncTable87Address 3189986056
#define EncTable88Address 3189986112
#define EncTable89Address 3189986168
#define EncTable90Address 3189986224
#define EncTable91Address 3189986280
#define EncTable92Address 3189986336
#define EncTable93Address 3189986392
#define EncTable94Address 3189986448
#define EncTable95Address 3189986504
#define EncTable96Address 3189986560
#define EncTable97Address 3189986616
#define EncTable98Address 3189986672
#define EncTable99Address 3189986728
#define EncTable100Address 3189986784
#define EncTable101Address 3189986840
#define EncTable102Address 3189986896
#define EncTable103Address 3189986952
#define EncTable104Address 3189987008
#define EncTable105Address 3189987064
#define EncTable106Address 3189987120
#define EncTable107Address 3189987176
#define EncTable108Address 3189987232
#define EncTable109Address 3189987288
#define EncTable110Address 3189987344
#define EncTable111Address 3189987400
#define EncTable112Address 3189987456
#define EncTable113Address 3189987512
#define EncTable114Address 3189987568
#define EncTable115Address 3189987624
#define EncTable116Address 3189987680
#define EncTable117Address 3189987736
#define EncTable118Address 3189987792
#define EncTable119Address 3189987848
#define EncTable120Address 3189987904
#define EncTable121Address 3189987960
#define EncTable122Address 3189988016
#define EncTable123Address 3189988072
#define EncTable124Address 3189988128
#define EncTable125Address 3189988184
#define EncTable126Address 3189988240
#define EncTable127Address 3189988296
#define EncTable128Address 3189988352
#define EncTable129Address 3189988408
#define EncTable130Address 3189988464
#define EncTable131Address 3189988520
#define EncTable132Address 3189988576
#define EncTable133Address 3189988632
#define EncTable134Address 3189988688
#define EncTable135Address 3189988744
#define EncTable136Address 3189988800
#define EncTable137Address 3189988856
#define EncTable138Address 3189988912
#define EncTable139Address 3189988968
#define EncTable140Address 3189989024
#define EncTable141Address 3189989080
#define EncTable142Address 3189989136
#define EncTable143Address 3189989192
#define EncTable144Address 3189989248
#define EncTable145Address 3189989304
#define EncTable146Address 3189989360
#define EncTable147Address 3189989416
#define EncTable148Address 3189989472
#define EncTable149Address 3189989528
#define EncTable150Address 3189989584
#define EncTable151Address 3189989640
#define EncTable152Address 3189989696
#define EncTable153Address 3189989752
#define EncTable154Address 3189989808
#define EncTable155Address 3189989864
#define EncTable156Address 3189989920
#define EncTable157Address 3189989976
#define EncTable158Address 3189990032
#define EncTable159Address 3189990088
#define EncTable160Address 3189990144
#define EncTable161Address 3189990200
#define EncTable162Address 3189990256
#define EncTable163Address 3189990312
#define EncTable164Address 3189990368
#define EncTable165Address 3189990424
#define EncTable166Address 3189990480
#define EncTable167Address 3189990536
#define EncTable168Address 3189990592
#define EncTable169Address 3189990648
#define EncTable170Address 3189990704
#define EncTable171Address 3189990760
#define EncTable172Address 3189990816
#define EncTable173Address 3189990872
#define EncTable174Address 3189990928
#define EncTable175Address 3189990984
#define EncTable176Address 3189991040
#define EncTable177Address 3189991096
#define EncTable178Address 3189991152
#define EncTable179Address 3189991208
#define EncTable180Address 3189991264
#define EncTable181Address 3189991320
#define EncTable182Address 3189991376
#define EncTable183Address 3189991432
#define EncTable184Address 3189991488
#define EncTable185Address 3189991544
#define EncTable186Address 3189991600
#define EncTable187Address 3189991656
#define EncTable188Address 3189991712
#define EncTable189Address 3189991768
#define EncTable190Address 3189991824
#define EncTable191Address 3189991880
#define EncTable192Address 3189991936
#define EncTable193Address 3189991992
#define EncTable194Address 3189992048
#define EncTable195Address 3189992104
#define EncTable196Address 3189992160
#define EncTable197Address 3189992216
#define EncTable198Address 3189992272
#define EncTable199Address 3189992328
#define EncTable200Address 3189992384
#define EncTable201Address 3189992440
#define EncTable202Address 3189992496
#define EncTable203Address 3189992552
#define EncTable204Address 3189992608
#define EncTable205Address 3189992664
#define EncTable206Address 3189992720
#define EncTable207Address 3189992776
#define EncTable208Address 3189992832
#define EncTable209Address 3189992888
#define EncTable210Address 3189992944
#define EncTable211Address 3189993000
#define EncTable212Address 3189993056
#define EncTable213Address 3189993112
#define EncTable214Address 3189993168
#define EncTable215Address 3189993224
#define EncTable216Address 3189993280
#define EncTable217Address 3189993336
#define EncTable218Address 3189993392
#define EncTable219Address 3189993448
#define EncTable220Address 3189993504
#define EncTable221Address 3189993560
#define EncTable222Address 3189993616
#define EncTable223Address 3189993672
#define EncTable224Address 3189993728
#define EncTable225Address 3189993784
#define EncTable226Address 3189993840
#define EncTable227Address 3189993896
#define EncTable228Address 3189993952
#define EncTable229Address 3189994008
#define EncTable230Address 3189994064
#define EncTable231Address 3189994120
#define EncTable232Address 3189994176
#define EncTable233Address 3189994232
#define EncTable234Address 3189994288
#define EncTable235Address 3189994344
#define EncTable236Address 3189994400
#define EncTable237Address 3189994456
#define EncTable238Address 3189994512
#define EncTable239Address 3189994568
#define EncTable240Address 3189994624
#define EncTable241Address 3189994680
#define EncTable242Address 3189994736
#define EncTable243Address 3189994792
#define EncTable244Address 3189994848
#define EncTable245Address 3189994904
#define EncTable246Address 3189994960
#define EncTable247Address 3189995016
#define EncTable248Address 3189995072
#define EncTable249Address 3189995128
#define EncTable250Address 3189995184
#define EncTable251Address 3189995240
#define EncTable252Address 3189995296
#define EncTable253Address 3189995352
#define EncTable254Address 3189995408
#define EncTable255Address 3189995464
Reply
#3
Just an update that Steve found a better way to do this:

pshm->Motor[0].pEnc = (int *) ((int)(&pshm->EncTable[2]) - (OffsetSHM << 2));

This is shorter and is firmware-version-independent. Just make sure you include gplib.h.
Reply
#4
Thanks this is neat and pleasing!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)