Sample Counter: Signed or Unsigned 32-Bit Integer?

[RMP 8.3.1], [RMP 10.3.1]

Is the value returned from MotionController::SampleCounterGet() really a signed integer?

Here’s the method signature

virtual int32 SampleCounterGet() = 0;

Suppose RMP ran until the sample counter was 0x7FFFFFFF. After the next time slice, would the function return 0x8000000 (a negative number with a large magnitude) or would it return 0 (since a negative sample count is kind of nonsense)?

(I thought asking the question would be quicker than waiting 24.85 days to see what would happen.)

Yep. It is a signed 32 bit integer. The only operation done on the number is a simple ++ every sample. You can always interpret the value however you like.

1 Like

So, when I ++ an int32_t,

	int32_t t = 0x7FFFFFF0;
	std::cout << std::hex << t << "\n";
	for (int32_t i=0; i<32; i++) {
		t++;
		std::cout << std::hex << t << "\n";
	}

I get something like

...
7ffffffd
7ffffffe
7fffffff
80000000
80000001
80000002
80000003
...

…which also means that I could interpret the value as an unsigned integer and get the full 32 bits of sample counter space.

Is this what you’d expect from RMP?

For example, what will RapidSetup display for the sample counter? Will it display a negative number?

Yes. That is what we would expect. If you’d like to experiment, use RapidSetup->Tools->Vm3. Hit F4. Sample Counter is the 11th item in the list. Type 8000000 and hit enter.

1 Like