## Matlab Function codes of the macros called in scripts

For Formula AllCode users to discuss projects, programs, and any other issues related to the Formula AllCode robotics platform.

Moderators: Benj, Mods

vivek26
Posts: 2
Joined: Fri Jun 09, 2017 10:58 am
Contact:

### Matlab Function codes of the macros called in scripts

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.
I require to modify and know how exactly things are so that i can utilize the maximum out of it.
Thanks!!!

Benj
Matrix Staff
Posts: 14950
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

### Re: Matlab Function codes of the macros called in scripts

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
Commands are always sent in the following format: Component ID, Function Index, Parameters, Returns

scicoco
Posts: 1
Joined: Tue Dec 03, 2019 10:30 pm
Contact:

### Re: Matlab Function codes of the macros called in scripts

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;

"""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]))
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

Benj
Matrix Staff
Posts: 14950
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

### Re: Matlab Function codes of the macros called in scripts

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.