Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Motor commutation; ACS command acsc_CommutExt not wrapped #19

Open
cbaurtx opened this issue Apr 7, 2019 · 7 comments
Open

Motor commutation; ACS command acsc_CommutExt not wrapped #19

cbaurtx opened this issue Apr 7, 2019 · 7 comments

Comments

@cbaurtx
Copy link
Contributor

cbaurtx commented Apr 7, 2019

Motor commutation

Some positioning systems (e.g. direct drive with missing hall sensors) need to calibrate the motor commutation. ACS controllers feature a auto commutate function.
This is supported by SPiiPlus C Library from version 2.5 on with the acsc_CommutExt function.

Description:
The function initiates motor commutation.
Syntax
Int acsc_CommutExt(HANDLE handle, int Axis, float Current, int Settle, int Slope, ACSC_WAITBLOCK *Wait)

Arguments:
Handle – Communication handle
Axis – The axis to perform commutation on. ACSC_AXIS_0 corresponds to axis0, ACSC_AXIS_1 –to axis1, etc.
Slope – Specifies the time it takes for the current to rise to the desired value, ACSC_NONE for default value.
Wait – Pointer to ACSC_WAITBLOCK structure.
If Wait is ACSC_SYNCHRONOUS, the function returns when the controller response is received. If Wait points to a valid ACSC_WAITBLOCK structure,
the function returns immediately. The calling thread must then call the acsc_WaitForAsyncCall function to retrieve the operation result.
If Wait is ACSC_IGNORE, the function returns immediately. In this case, the operation result is ignored by the library and cannot be retrieved to the
calling thread.

C Example use:
if(!acsc_CommutExt(Handle,// Communication handle
ACSC_AXIS_0, // Commuting axis 0
43, // Commutation current
ACS_NONE, // Use default settle
ACS_NONE, // Use default slope
ACSC_SYNCHRONOUS // Waiting call
)){
printf(“commutation error: %d\n”,acsc_GetLastError());
}

Can you add this?

@petebachant
Copy link
Owner

This should be pretty easy to add to the acsc module, following the example pattern here: https://github.com/petebachant/ACSpy/blob/master/acspy/acsc.py#L328

I don't currently have access to an ACS controller. Could you put together a PR for this addition?

@cbaurtx
Copy link
Contributor Author

cbaurtx commented Apr 7, 2019

I will put a pull request. I just have added that function, but tested only in simulation.
It will be only in 2-3 weeks that I have access to a system with controller.
I also started to add exception handling. So 0 return values from calls to the acsc library, which indicate an error do not get lost. I can add that as well, if you are OK with this

Christof

@cbaurtx cbaurtx closed this as completed Apr 7, 2019
@petebachant
Copy link
Owner

If you want to submit it now, I have no problem merging. I will also keep this issue open until resolved. Thanks!

@petebachant petebachant reopened this Apr 7, 2019
@cbaurtx
Copy link
Contributor Author

cbaurtx commented Apr 14, 2019

Pete,

unfortunately our ACS hardware is hung-up in customs, so I am still limited to simulation.
Nevertheless I made some progress, but I would like to check with real hardware before committing anything. Here is a summary:

  1. The loadBuffersFromFile function always returns with an error that my file is not ANSI. I checked
    the file format and it should be OK
  2. Error handling
    print statements go only so far. So I defined a custom exception:
    class AcscError(Exception): def __init__(self, *args, **kwargs): Exception.__init__(self, *args, **kwargs)
    and a wrapper function checking for ACS errors:
    def call_acsc(func, *args, **kwargs): rv = func(*args, **kwargs) if rv == 0: err = acs.acsc_GetLastError() if err in errors: raise AcscError(str(err) + ': ' + errors[err]) else: raise AcscError(err) return rv
    this is used like this:
    def getProgramState(hc, nbuf, wait=SYNCHRONOUS): """Returns program state""" state = ctypes.c_int() call_acsc(acs.acsc_GetProgramState, hc, nbuf, byref(state), wait) return state.value
    Please be aware that if we change to error handling by means of exceptions this
    will break existing code which relies on ACS errors being dropped quietly.

Regards Christof

@cbaurtx cbaurtx closed this as completed Apr 14, 2019
@petebachant
Copy link
Owner

I think that all sounds good. If you want to submit a PR early for code review purposes, you can just call it out as WIP. Don't worry about additional commits you may need after debugging with real hardware. I can wait before merging.

@petebachant petebachant reopened this Apr 14, 2019
@cbaurtx
Copy link
Contributor Author

cbaurtx commented Apr 26, 2019

Pete,
I now have code worth committing. Do I need rights to push this code?

Current state:
Some basic tests performed using the ACS simulator. Tests done in Python 3.7.0

  1. Enhanced error handling: use the ACS library to get error string for all errors. So error.py is not needed
    any more.
  2. Added functions to read, set and clear motor flags (Mflags)
  3. Added function to commutate and to wait until commutation is done
  4. Added functions to read and set killDecelaration (used for emergency stop)
  5. Fixed loadBuffersFromFile with a workaround which reverts to loadBuffer

acsc.zip

@petebachant
Copy link
Owner

Cool! Nope, you don't need permissions. The best way to do this is and do some code review to use the fork/pull process:

  1. Create a fork (use the "fork" button in the top right of this page)
  2. Clone your fork locally git clone ...
  3. Create a branch in the local repo git checkout -b my-additions
  4. Copy your modified files into that repository and check they look right with git status and git diff
  5. Commit your changes git add . then `git commit -m "Add more ACSC functionality"
  6. git push origin my-additions -- after you do this the terminal will tell you the link to open the PR; visit that and open one up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants