Page 1 of 1

Matlab Function codes of the macros called in scripts

Posted: Fri Jun 09, 2017 11:10 am
by vivek26
Hi there,
I need to know how exactly the commands like Forwards , SetMotors work. i.e in the Matlab script of these functions there are statements of fwrite which i see are calling again to some another macro listed by numbers like 2,3,4,5etc. in the script.
If it is possible could you please upload the macros details.
I require to modify and know how exactly things are so that i can utilize the maximum out of it.
Thanks!!!

Re: Matlab Function codes of the macros called in scripts

Posted: Tue Jun 13, 2017 12:19 pm
by Benj
Hello,

The Formula AllCode works in binary mode and string mode. The Matlab scripts are accessing the binary mode to help speed up communications.

This document contains the overview of the binary and string modes and should help you to get the right command numbers.
Command API.xlsx
(18.58 KiB) Downloaded 479 times
Commands are always sent in the following format: Component ID, Function Index, Parameters, Returns

Re: Matlab Function codes of the macros called in scripts

Posted: Tue Dec 03, 2019 10:40 pm
by scicoco
Hello,

I'm currently working for some projects with students but with Python. Inspired by the Matlab's API, I suggest you to add this two python's API function in FA.py based on "binary mode" :

def EncoderReset(self):
"""Resets the motor encoder counters
"""
self.__ser.write(bytearray([0, 14]))
return;


def EncoderRead(self, index):
"""Reads one of the motor encoder counters
Approx 0.328296mm of travel per encoder unit.

Args:
index: value of encoder (0=Left, 1=Right)

Returns:
int: Value of the encoder counter

"""
self._flush()
self.__ser.write(bytearray([0, 15, index]))
ret = self.__ser.read(2)
r = ret[1]<<8 | ret[0]
return(r);

Maybe some other Python's API function should be rewritten/added with the binary mode if that could improve speed up communication.
Regards,
Alan

Re: Matlab Function codes of the macros called in scripts

Posted: Wed Dec 04, 2019 12:35 pm
by Benj
Hi Alan,

Thanks for that I wasn't aware the API for Python wasn't already using the binary mode. It certainly will run faster than the string mode as it can jump directly to the correct command rather then having to parse through the string and do string comparisons.

I'll investigate this when I get some time thanks.