Is encoder count signed or unsigned?

Questions about using encoders with the Roboclaw product line
mitch
Posts: 1
Joined: Wed Jun 06, 2018 9:39 am

Is encoder count signed or unsigned?

Postby mitch » Thu Jun 07, 2018 7:21 am

Can you clarify whether the encoder count is signed or unsigned? I see some conflicting information:

1. In RoboClaw.h: SetEncM1(uint8_t address, int32_t val);

2. In RoboClaw.h: uint32_t ReadEncM1(uint8_t address, uint8_t *status=NULL,bool *valid=NULL);

3. In RoboClaw.h: SpeedAccelDeccelPositionM1(uint8_t address, uint32_t accel, uint32_t speed, uint32_t deccel, uint32_t position, uint8_t flag);

4. In RoboClaw Series User Manual p.99: int32_t enc2 = roboclaw.ReadEncM2(address, &status2, &valid2);

5. In IonStudio, position control appears to be signed.

Thank you.

User avatar
Basicmicro Support
Posts: 905
Joined: Thu Feb 26, 2015 9:45 pm

Re: Is encoder count signed or unsigned?

Postby Basicmicro Support » Wed Jun 13, 2018 10:05 am

Both ReadEncM# commands return a uint32_t(based on the roboclaw.h and roboclaw.cpp files I just looked at sothis is a typo in the user manual.

Because of some idiosyncracies with Arduino(and GCC) the ReadEncM# and SpeedAccelDeccelPosition commands use unsigned variables. However you can store those values in signed 32bit variables just fine and get the correct +- ranges.

A signed 32bit variable is used with the SetEnc commands for a similar reason but I dont remember the exact reason it couldnt use an unsigned value.

In general if you use signed variables for all your commands you will be fine.

rwschumann
Posts: 2
Joined: Wed Jun 20, 2018 7:39 am

Re: Is encoder count signed or unsigned?

Postby rwschumann » Wed Jun 20, 2018 8:21 am

Note this issue also exists as it relates to the position based commands.

If the encoder is really a signed value, which I would suggest is the correct approach, then it needs to be used consistently including with position.

thanks,
Rob


Return to “Velocity and Position Control”

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

cron