Latest revision |
Your text |
Line 141: |
Line 141: |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | Below an alternative code that writes one variable (absolute setpoint) and read three variables (torque, position and velocity feedbacks). This code is present in live demo in [https://github.com/GraniteDevices/SMV2Commander SMV2Commander example].
| |
− | <syntaxhighlight lang="c">
| |
− |
| |
− | //VALUES DEFINED
| |
− | int paramAddr1=SMP_ABSOLUTE_SETPOINT;
| |
− | int paramValue1=0;//your setpoint value
| |
− | int readOutParamAddr1=SMP_ACTUAL_TORQUE;
| |
− | int readOutParamAddr2=SMP_ACTUAL_POSITION_FB;
| |
− | int readOutParamAddr3=SMP_ACTUAL_VELOCITY_FB;
| |
− | smint32 nul, readout1, readout2, readout3;
| |
− |
| |
− | //WRITING PARAMETERS
| |
− | //set an parameter number where next values are written. This line consumes 2 bytes of outbound payload
| |
− | smAppendSMCommandToQueue( busHandle, SMPCMD_SETPARAMADDR, paramAddr1 );
| |
− |
| |
− | //write the parameter value to previously set parameter address. SMPCMD_24B consumes 3 bytes of outbound payload
| |
− | smAppendSMCommandToQueue( busHandle, SMPCMD_24B, paramValue1);
| |
− |
| |
− | //READING PARAMETERS
| |
− | //set parameter parameter number which will be returned from each command executed after this
| |
− | smAppendSMCommandToQueue( busHandle, SMPCMD_SETPARAMADDR, SMP_RETURN_PARAM_ADDR ); //consumes 2 bytes
| |
− | /*write new values to parameter SMP_RETURN_PARAM_ADDR. after execution these commands return the parameter values
| |
− | defined by readOutParamAddrN*/
| |
− | smAppendSMCommandToQueue( busHandle, SMPCMD_24B, readOutParamAddr1 ); //consumes 3 bytes
| |
− | smAppendSMCommandToQueue( busHandle, SMPCMD_24B, readOutParamAddr2 ); //consumes 3 bytes
| |
− | smAppendSMCommandToQueue( busHandle, SMPCMD_24B, readOutParamAddr3 ); //consumes 3 bytes
| |
− |
| |
− | //execute commands over SM bus
| |
− | smExecuteCommandQueue( busHandle, deviceAddress );
| |
− |
| |
− | /*read value commands (one per each append command). Size of inbound payload depends on
| |
− | what was set to SMP_RETURN_PARAM_LEN at initialization */
| |
− | smGetQueuedSMCommandReturnValue( busHandle,&nul );
| |
− | smGetQueuedSMCommandReturnValue( busHandle,&nul );
| |
− |
| |
− | smGetQueuedSMCommandReturnValue( busHandle,&nul );
| |
− |
| |
− | /*the next readouts reflect to the last three commands appended before smExecuteCommandQueue
| |
− | and here we get the readout values*/
| |
− |
| |
− | smGetQueuedSMCommandReturnValue( busHandle,&readout1 );
| |
− | smGetQueuedSMCommandReturnValue( busHandle,&readout2 );
| |
− | smGetQueuedSMCommandReturnValue( busHandle,&readout3 );
| |
− |
| |
− | //TODO add some SM error checking in appropriate places
| |
− | </syntaxhighlight>
| |
| ====Writing multiple and reading single value at one cycle==== | | ====Writing multiple and reading single value at one cycle==== |
| If we need to read only one variable, we don't need to change readout parameter address during cycle and further improve performance. In this case we set it at initialization and then all consequent commands will return the desired return value. | | If we need to read only one variable, we don't need to change readout parameter address during cycle and further improve performance. In this case we set it at initialization and then all consequent commands will return the desired return value. |
Line 269: |
Line 223: |
| //TODO add some SM error checking in appropriate places | | //TODO add some SM error checking in appropriate places |
| </syntaxhighlight> | | </syntaxhighlight> |
− | ==See also==
| |
− | *[[Changing SimpleMotion baud rate]]
| |
− | [[Category:Development]]
| |
− | [[Category:SimpleMotion]]
| |