From 3e9e8397f186f69e9b12691bc2f92077bfab484e Mon Sep 17 00:00:00 2001 From: Tero Kontkanen Date: Thu, 4 Feb 2016 02:06:01 +0200 Subject: Add compatibility to MSVC compiler --- simplemotion_private.h | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/simplemotion_private.h b/simplemotion_private.h index d1e37a3..1c80780 100644 --- a/simplemotion_private.h +++ b/simplemotion_private.h @@ -46,6 +46,13 @@ void smDebug( smbus handle, smVerbosityLevel verbositylevel, char *format, ...); SM_STATUS smRawCmd( const char *axisname, smuint8 cmd, smuint16 val, smuint32 *retdata ); +/*Workaround to have packed structs that compile on GCC and MSVC*/ +#ifdef __GNUC__ +#define PACKED __attribute__ ((__packed__)) +#else/*Assuming MSVC*/ +#define PACKED +#pragma pack(push,1) +#endif typedef struct { /* ID=0 param size 30 bits (cmd total 4 bytes) @@ -55,7 +62,7 @@ typedef struct { */ long param :30; //LSB 30 bits long ID:2; //MSB 2 bits. when serailzied to bytestream byte4 must be transmitted first to contain ID -} __attribute__ ((packed)) SMPayloadCommand32; +} PACKED SMPayloadCommand32; typedef struct { /* ID=0 param size 30 bits (cmd total 4 bytes) @@ -65,7 +72,7 @@ typedef struct { */ long param :14; //LSB 30 bits long ID:2; //MSB 2 bits. when serailzied to bytestream byte4 must be transmitted first to contain ID -} __attribute__ ((packed)) SMPayloadCommand16; +} PACKED SMPayloadCommand16; typedef struct { /* ID=0 param size 30 bits (cmd total 4 bytes) @@ -75,7 +82,7 @@ typedef struct { */ long param :22; //MSB 30 bits long ID:2; //MSB 2 bits. when serailzied to bytestream byte4 must be transmitted first to contain ID -} __attribute__ ((packed)) SMPayloadCommand24; +} PACKED SMPayloadCommand24; //SM payload command return data structure typedef struct { @@ -86,7 +93,8 @@ typedef struct { */ long retData: 30; //LSB 30 bits long ID:2; //MSB 2 bits. when serailzied to bytestream byte4 must be transmitted first to contain ID -} __attribute__ ((packed)) SMPayloadCommandRet32; +} PACKED SMPayloadCommandRet32; + //SM payload command return data structure typedef struct { /* ID=0 ret data 30 bits (tot 4 bytes) @@ -96,7 +104,8 @@ typedef struct { */ long retData: 22; //LSB 30 bits long ID:2; //MSB 2 bits. when serailzied to bytestream byte4 must be transmitted first to contain ID -} __attribute__ ((packed)) SMPayloadCommandRet24; +} PACKED SMPayloadCommandRet24; + //SM payload command return data structure typedef struct { /* ID=0 ret data 30 bits (tot 4 bytes) @@ -106,7 +115,8 @@ typedef struct { */ long retData: 14; //LSB 30 bits long ID:2; //MSB 2 bits. when serailzied to bytestream byte4 must be transmitted first to contain ID -} __attribute__ ((packed)) SMPayloadCommandRet16; +} PACKED SMPayloadCommandRet16; + //SM payload command return data structure typedef struct { /* ID=0 ret data 30 bits (tot 4 bytes) @@ -116,6 +126,14 @@ typedef struct { */ long retData: 6; //LSB 30 bits long ID:2; //MSB 2 bits. when serailzied to bytestream byte4 must be transmitted first to contain ID -} __attribute__ ((packed)) SMPayloadCommandRet8; +} PACKED SMPayloadCommandRet8; + +/*Workaround to have packed structs that compile on GCC and MSVC*/ +#ifdef __GNUC__ +#else/*Assuming MSVC*/ +#pragma pack(pop) +#undef PACKED +#endif + #endif // SIMPLEMOTION_PRIVATE_H -- cgit v1.2.3 From 50fa0966f9c784cebc026889ebdc48bbf5068a1e Mon Sep 17 00:00:00 2001 From: Tero Kontkanen Date: Mon, 29 Feb 2016 19:03:19 +0200 Subject: Added torque mode modifiers & effects definitions --- simplemotion_defs.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/simplemotion_defs.h b/simplemotion_defs.h index d5f6630..f4c0dc5 100644 --- a/simplemotion_defs.h +++ b/simplemotion_defs.h @@ -446,6 +446,25 @@ //anti dither limits #define SMP_ANTIDITHER_MODE 230 +//torque modifiers & effects +/*SMP_TORQUE_NOTCH_FILTER contains 3 values in different bit positions: + * 0-7 (lowest byte), attenuation in 0.1dB steps and value V=1-255 means attenuation of (-V-255)/10 dB gain. if V set 0, use notch filter instead of peaking with "infinite" attenuation. value 255 disables notch filter. + * 8-15, Q factor in 0.1 steps + * 16-30, center frequency in 0.2Hz steps so range is 0-1638.3 Hz. value 0 disables the filter. + * + *Example, peaking filter with gain -12.5dB, center freq 1000Hz and Q=5.5 value is: 0x01F43782 (0x01f4=1000/2, 0x37=5.5*10, 0x82=255-12.5*10) + *Example, peaking filter with gain -11.5dB, center freq 20Hz and Q=3.5 value is: 0x00648c23 = dec 6589475 + * + *Notch filter works in all control modes + */ +#define SMP_TORQUE_NOTCH_FILTER 240 +//define damping effect gain in torque control mode, torque added to setpoint equals -speed*gain with +#define SMP_TORQUE_EFFECT_DAMPING 241 +//define friction effect gain in torque control mode +#define SMP_TORQUE_EFFECT_FRICTION 242 +//define inertia effect gain in torque control mode, torque added to setpoint equals -acceleration*gain +#define SMP_TORQUE_EFFECT_INERTIA 243 + //secondary feedback loop 300-399 //NOT IMPLEMENTED YET -- cgit v1.2.3 From 3efac208723dc1cb8a0cc81c728196bdc3fbd424 Mon Sep 17 00:00:00 2001 From: Tero K Date: Wed, 2 Mar 2016 23:44:00 +0200 Subject: Redefined notch filter parameter meaning --- simplemotion_defs.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/simplemotion_defs.h b/simplemotion_defs.h index f4c0dc5..9752e4f 100644 --- a/simplemotion_defs.h +++ b/simplemotion_defs.h @@ -449,13 +449,12 @@ //torque modifiers & effects /*SMP_TORQUE_NOTCH_FILTER contains 3 values in different bit positions: * 0-7 (lowest byte), attenuation in 0.1dB steps and value V=1-255 means attenuation of (-V-255)/10 dB gain. if V set 0, use notch filter instead of peaking with "infinite" attenuation. value 255 disables notch filter. - * 8-15, Q factor in 0.1 steps - * 16-30, center frequency in 0.2Hz steps so range is 0-1638.3 Hz. value 0 disables the filter. + * 8-15, Q factor in 0.1 steps. Minimum is 0.1, below that filter is disabled. + * 16-29, center frequency in 0.1Hz steps, and 1.1Hz is minimum, so range is 1.1-409.5 Hz. value below or equal 1Hz disables the filter. * - *Example, peaking filter with gain -12.5dB, center freq 1000Hz and Q=5.5 value is: 0x01F43782 (0x01f4=1000/2, 0x37=5.5*10, 0x82=255-12.5*10) *Example, peaking filter with gain -11.5dB, center freq 20Hz and Q=3.5 value is: 0x00648c23 = dec 6589475 * - *Notch filter works in all control modes + *Notch filter works in all control modes and is applied to torque controller setpoint */ #define SMP_TORQUE_NOTCH_FILTER 240 //define damping effect gain in torque control mode, torque added to setpoint equals -speed*gain with -- cgit v1.2.3 From 9894a06151def6720c1f967f5f18fd7111becd82 Mon Sep 17 00:00:00 2001 From: Tero Kontkanen Date: Wed, 30 Mar 2016 18:03:28 +0300 Subject: Add EL_MODE_SIMUCUBE for IONI --- simplemotion_defs.h | 1 + 1 file changed, 1 insertion(+) diff --git a/simplemotion_defs.h b/simplemotion_defs.h index 9752e4f..be8ee95 100644 --- a/simplemotion_defs.h +++ b/simplemotion_defs.h @@ -433,6 +433,7 @@ #define EL_MODE_STANDARD 0 #define EL_MODE_IONICUBE 1 #define EL_MODE_IONIZER 2 + #define EL_MODE_SIMUCUBE 3 //primary feedback loop 200-299 -- cgit v1.2.3 From ae182289686ce272ba7f5080b482d8edfd177441 Mon Sep 17 00:00:00 2001 From: Tero Kontkanen Date: Thu, 31 Mar 2016 00:16:16 +0300 Subject: Swap EL_MODE 2 and 3 because EL_MODE_IONIZER is not used (at least yet) --- simplemotion_defs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simplemotion_defs.h b/simplemotion_defs.h index be8ee95..29e040d 100644 --- a/simplemotion_defs.h +++ b/simplemotion_defs.h @@ -432,8 +432,8 @@ #define SMP_ELECTRICAL_MODE 573 #define EL_MODE_STANDARD 0 #define EL_MODE_IONICUBE 1 - #define EL_MODE_IONIZER 2 - #define EL_MODE_SIMUCUBE 3 + #define EL_MODE_SIMUCUBE 2 + #define EL_MODE_IONIZER 3 //primary feedback loop 200-299 -- cgit v1.2.3 From ce55c8a4227539f4d4f57f7acc4aaff1d18c0001 Mon Sep 17 00:00:00 2001 From: Tero K Date: Mon, 18 Apr 2016 15:04:51 +0300 Subject: Added SMP_SERIAL_ENC_BITS definition --- simplemotion_defs.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/simplemotion_defs.h b/simplemotion_defs.h index 29e040d..f171350 100644 --- a/simplemotion_defs.h +++ b/simplemotion_defs.h @@ -435,6 +435,13 @@ #define EL_MODE_SIMUCUBE 2 #define EL_MODE_IONIZER 3 +/*for BiSS encoder + * bits defined as: + * lowest 8 bits: single turn bits, value range 4-24 + * next 8 bits: multi turn bits, value range 0-16 + * rest: reserved for future use (always 0) + */ +#define SMP_SERIAL_ENC_BITS 574 //primary feedback loop 200-299 #define SMP_VEL_I 200 -- cgit v1.2.3 From fa9c9212d7e25e9eacbbfcc4e6a516b4d48ebbb5 Mon Sep 17 00:00:00 2001 From: Tero Kontkanen Date: Fri, 28 Oct 2016 15:18:18 +0300 Subject: Added smSetBaudrate() to allow changing bus speed --- busdevice.c | 4 +++- rs232.c | 36 ++++++++++++++++++++++++++++++++++++ simplemotion.c | 21 +++++++++++++++++++++ simplemotion.h | 18 ++++++++++++++++++ simplemotion_private.h | 1 + 5 files changed, 79 insertions(+), 1 deletion(-) diff --git a/busdevice.c b/busdevice.c index 9bf82c8..c82e27b 100644 --- a/busdevice.c +++ b/busdevice.c @@ -10,6 +10,8 @@ //how much bytes available in transmit buffer #define TANSMIT_BUFFER_LENGTH 128 +unsigned long SMBusBaudrate=SM_BAUDRATE; //the next opened port (with smOpenBus) will be opened with the PBS defined here (default 460800 BPS) + typedef struct _SMBusDevice { //common @@ -65,7 +67,7 @@ smbusdevicehandle smBDOpen( const char *devicename ) if(strncmp(devicename,"COM",3) == 0 || strncmp(devicename,"/dev/tty",8) == 0) //use rs232 lib { - BusDevice[handle].comPort=OpenComport( devicename, SM_BAUDRATE ); + BusDevice[handle].comPort=OpenComport( devicename, SMBusBaudrate ); if( BusDevice[handle].comPort == -1 ) { return -1; //failed to open diff --git a/rs232.c b/rs232.c index 1773767..4055e2a 100644 --- a/rs232.c +++ b/rs232.c @@ -93,6 +93,20 @@ int OpenComport(const char * comport_name, int baudrate) break; case 1000000 : baudr = B1000000; break; + case 1115200 : baudr = B1152000; + break; + case 1500000 : baudr = B1500000; + break; + case 2000000 : baudr = B2000000; + break; + case 2500000 : baudr = B2500000; + break; + case 3000000 : baudr = B3000000; + break; + case 3500000 : baudr = B3500000; + break; + case 4000000 : baudr = B4000000; + break; default : printf("invalid baudrate\n"); return(1); break; @@ -254,6 +268,28 @@ int OpenComport(const char * comport_name, int baudrate) break; case 460800 : strcpy(baudr, "baud=460800 data=8 parity=N stop=1"); break; + case 500000 : strcpy(baudr, "baud=500000 data=8 parity=N stop=1"); + break; + case 576000 : strcpy(baudr, "baud=576000 data=8 parity=N stop=1"); + break; + case 921600 : strcpy(baudr, "baud=921600 data=8 parity=N stop=1"); + break; + case 1000000 : strcpy(baudr, "baud=1000000 data=8 parity=N stop=1"); + break; + case 1115200 : strcpy(baudr, "baud=1115200 data=8 parity=N stop=1"); + break; + case 1500000 : strcpy(baudr, "baud=1500000 data=8 parity=N stop=1"); + break; + case 2000000 : strcpy(baudr, "baud=2000000 data=8 parity=N stop=1"); + break; + case 2500000 : strcpy(baudr, "baud=2500000 data=8 parity=N stop=1"); + break; + case 3000000 : strcpy(baudr, "baud=3000000 data=8 parity=N stop=1"); + break; + case 3500000 : strcpy(baudr, "baud=3500000 data=8 parity=N stop=1"); + break; + case 4000000 : strcpy(baudr, "baud=4000000 data=8 parity=N stop=1"); + break; default : printf("invalid baudrate\n"); return(-1); break; diff --git a/simplemotion.c b/simplemotion.c index cea0238..ea773ac 100644 --- a/simplemotion.c +++ b/simplemotion.c @@ -222,6 +222,27 @@ smbus smOpenBus( const char * devicename ) return handle; } +/** Change baudrate of SM communication port. This does not affect already opened ports but the next smOpenBus will be opened at the new speed. + Calling this is optional. By default SM bus and all slave devices operates at 460800 BPS speed. + Parameters: + -bps: bus speed in bits per second. for possible choices, see rs232.c (but note that all speeds are not necessarily supported by SM devices) + Typical usage is: + - first call smSetParameter(handle,0,SMP_BUS_SPEED,N) to change speed of all connected slaves to N PBS + - then close port with smCloseBus + - then call smSetBaudrate(N) + - then open bus again with smOpenBus + + Note that in upcoming SM device firmware versions, bitrate will be reset to default (460800) if device side SM bus watchdog timer has been enabled, and it timeouts. + This allows re-establishing connection at defautl speed if connection breaks up and SM bus watchdog timeout gets exceeded. To identify is device supports this, + read parameter SMP_SM_VERSION. Values above 25 support this feature. Value 25 and below will not reset baudrate. + + Note also that SMP_BUS_SPEED will not be saved in device flash memory - it will reset to default at every reset & power on. + */ +LIB void smSetBaudrate( unsigned long pbs ) +{ + SMBusBaudrate=pbs; +} + /** Close connection to given bus handle number. This frees communication link therefore makes it available for other apps for opening. -return value: a SM_STATUS value, i.e. SM_OK if command succeed */ diff --git a/simplemotion.h b/simplemotion.h index 056c745..913a595 100644 --- a/simplemotion.h +++ b/simplemotion.h @@ -81,6 +81,24 @@ typedef enum _smVerbosityLevel {Off,Low,Mid,High,Trace} smVerbosityLevel; */ LIB smbus smOpenBus( const char * devicename ); +/** Change baudrate of SM communication port. This does not affect already opened ports but the next smOpenBus will be opened at the new speed. + Calling this is optional. By default SM bus and all slave devices operates at 460800 BPS speed. + Parameters: + -bps: bus speed in bits per second. for possible choices, see rs232.c (but note that all speeds are not necessarily supported by SM devices) + Typical usage is: + - first call smSetParameter(handle,0,SMP_BUS_SPEED,N) to change speed of all connected slaves to N PBS + - then close port with smCloseBus + - then call smSetBaudrate(N) + - then open bus again with smOpenBus + + Note that in upcoming SM device firmware versions, bitrate will be reset to default (460800) if device side SM bus watchdog timer has been enabled, and it timeouts. + This allows re-establishing connection at defautl speed if connection breaks up and SM bus watchdog timeout gets exceeded. To identify is device supports this, + read parameter SMP_SM_VERSION. Values above 25 support this feature. Value 25 and below will not reset baudrate. + + Note also that SMP_BUS_SPEED will not be saved in device flash memory - it will reset to default at every reset & power on. + */ +LIB void smSetBaudrate( unsigned long pbs ); + /** Set timeout of how long to wait reply packet from bus. Must be set before smOpenBus and cannot be changed afterwards * max value 5000ms. In unix this is rounded to 100ms (rounding downwards), so 99 or less gives 0ms timeout. * diff --git a/simplemotion_private.h b/simplemotion_private.h index 1c80780..e46dc1c 100644 --- a/simplemotion_private.h +++ b/simplemotion_private.h @@ -30,6 +30,7 @@ #define BUSDEV_FTDI 2 /*not implemented yet: direct FTDI lib support*/ #define SM_BUSDEVICENAME_LEN 64 +extern unsigned long SMBusBaudrate; //the next opened port (with smOpenBus) will be opened with the PBS defined here (default 460800 BPS) //default timeout in ms //Argon drive's worst case response time should be ~20ms with max length packets -- cgit v1.2.3