PebbleOS v4.47.0-1219-g7c542d7a9
Loading...
Searching...
No Matches
CiA 402 drive

Drive profile (CiA 402) on a CANopen node. More...

Data Structures

struct  pbl_cia402_ops
 Drive callbacks, each optional. More...
 
struct  pbl_cia402
 A drive. More...
 

Macros

#define PBL_CIA402_CONTROLWORD   0x6040U
 Controlword.
 
#define PBL_CIA402_STATUSWORD   0x6041U
 Statusword.
 
#define PBL_CIA402_MODES_OF_OPERATION   0x6060U
 Modes of operation.
 
#define PBL_CIA402_MODES_OF_OPERATION_DISPLAY   0x6061U
 Modes of operation display.
 

Enumerations

enum  pbl_cia402_mode {
  PBL_CIA402_MODE_NONE = 0 , PBL_CIA402_MODE_PROFILE_POSITION = 1 , PBL_CIA402_MODE_PROFILE_VELOCITY = 3 , PBL_CIA402_MODE_PROFILE_TORQUE = 4 ,
  PBL_CIA402_MODE_CYCLIC_POSITION = 8 , PBL_CIA402_MODE_CYCLIC_VELOCITY = 9 , PBL_CIA402_MODE_CYCLIC_TORQUE = 10
}
 Modes of operation. More...
 
enum  pbl_cia402_state {
  PBL_CIA402_NOT_READY_TO_SWITCH_ON , PBL_CIA402_SWITCH_ON_DISABLED , PBL_CIA402_READY_TO_SWITCH_ON , PBL_CIA402_SWITCHED_ON ,
  PBL_CIA402_OPERATION_ENABLED , PBL_CIA402_QUICK_STOP_ACTIVE , PBL_CIA402_FAULT_REACTION_ACTIVE , PBL_CIA402_FAULT
}
 States of the drive. More...
 

Functions

int pbl_cia402_init (struct pbl_cia402 *drive, struct pbl_canopen *co, const struct pbl_cia402_ops *ops, void *arg)
 Attach a drive to a node, initialized and not started, in switch on disabled.
 
enum pbl_cia402_state pbl_cia402_state (struct pbl_cia402 *drive)
 Get the state of a drive.
 
enum pbl_cia402_mode pbl_cia402_mode (struct pbl_cia402 *drive)
 Get the mode of operation of a drive.
 
int pbl_cia402_fault (struct pbl_cia402 *drive, uint16_t code)
 Report a fault: the drive goes to fault reaction active, sets the error code (0x603f) and raises an emergency.
 
void pbl_cia402_fault_reaction_done (struct pbl_cia402 *drive)
 End the fault reaction: the drive goes to fault, until the master resets it.
 
void pbl_cia402_quick_stop_done (struct pbl_cia402 *drive)
 End a quick stop: the drive goes to switch on disabled, or stays in quick stop active with quick stop option codes 5 to 8.
 
void pbl_cia402_set_status (struct pbl_cia402 *drive, uint16_t mask, uint16_t bits)
 Set statusword bits the application owns, PBL_CIA402_SW_* ones.
 

Statusword bits the application sets

#define PBL_CIA402_SW_WARNING   PBL_BIT(7)
 Warning.
 
#define PBL_CIA402_SW_TARGET_REACHED   PBL_BIT(10)
 Target reached.
 
#define PBL_CIA402_SW_INTERNAL_LIMIT   PBL_BIT(11)
 Internal limit active.
 
#define PBL_CIA402_SW_MODE_SPECIFIC   (PBL_BIT(12) | PBL_BIT(13))
 Operation mode specific bits.
 
#define PBL_CIA402_SW_MANUFACTURER   (PBL_BIT(14) | PBL_BIT(15))
 Manufacturer specific bits.
 

Detailed Description

Drive profile (CiA 402) on a CANopen node.

A drive runs the CiA 402 state machine of a node whose object dictionary has a cia402 section: the controlword (0x6040) the master writes moves it from state to state, and the statusword (0x6041) reports it. The application drives the motor from its callbacks, all called with the node locked:

static int prv_enable(struct pbl_cia402 *drive, void *arg) {
motor_enable();
return 0;
}
static const struct pbl_cia402_ops s_ops = {.enable = prv_enable, .disable = prv_disable};
ret = pbl_canopen_init(&s_co, &cfg);
ret = pbl_cia402_init(&s_drive, &s_co, &s_ops, nullptr);
ret = pbl_canopen_start(&s_co);
A drive.
Definition cia402.h:124
int pbl_cia402_init(struct pbl_cia402 *drive, struct pbl_canopen *co, const struct pbl_cia402_ops *ops, void *arg)
Attach a drive to a node, initialized and not started, in switch on disabled.
int pbl_canopen_init(struct pbl_canopen *co, const struct pbl_canopen_config *cfg)
Initialize a node, stopped.
int pbl_canopen_start(struct pbl_canopen *co)
Start the node: join the bus, restore every default and go pre-operational.
Drive callbacks, each optional.
Definition cia402.h:97
int(* enable)(struct pbl_cia402 *drive, void *arg)
Enable the motor, to follow its targets.
Definition cia402.h:103

The motor follows its targets, e.g. 0x607a or 0x60ff, while the drive is operation enabled. The functions lock the node, so they are called from a thread or a callback, never an interrupt.


Data Structure Documentation

◆ pbl_cia402

struct pbl_cia402

A drive.

Macro Definition Documentation

◆ PBL_CIA402_CONTROLWORD

#define PBL_CIA402_CONTROLWORD   0x6040U

Controlword.

◆ PBL_CIA402_MODES_OF_OPERATION

#define PBL_CIA402_MODES_OF_OPERATION   0x6060U

Modes of operation.

◆ PBL_CIA402_MODES_OF_OPERATION_DISPLAY

#define PBL_CIA402_MODES_OF_OPERATION_DISPLAY   0x6061U

Modes of operation display.

◆ PBL_CIA402_STATUSWORD

#define PBL_CIA402_STATUSWORD   0x6041U

Statusword.

◆ PBL_CIA402_SW_INTERNAL_LIMIT

#define PBL_CIA402_SW_INTERNAL_LIMIT   PBL_BIT(11)

Internal limit active.

◆ PBL_CIA402_SW_MANUFACTURER

#define PBL_CIA402_SW_MANUFACTURER   (PBL_BIT(14) | PBL_BIT(15))

Manufacturer specific bits.

◆ PBL_CIA402_SW_MODE_SPECIFIC

#define PBL_CIA402_SW_MODE_SPECIFIC   (PBL_BIT(12) | PBL_BIT(13))

Operation mode specific bits.

◆ PBL_CIA402_SW_TARGET_REACHED

#define PBL_CIA402_SW_TARGET_REACHED   PBL_BIT(10)

Target reached.

◆ PBL_CIA402_SW_WARNING

#define PBL_CIA402_SW_WARNING   PBL_BIT(7)

Warning.

Enumeration Type Documentation

◆ pbl_cia402_mode

Modes of operation.

Enumerator
PBL_CIA402_MODE_NONE 
PBL_CIA402_MODE_PROFILE_POSITION 
PBL_CIA402_MODE_PROFILE_VELOCITY 
PBL_CIA402_MODE_PROFILE_TORQUE 
PBL_CIA402_MODE_CYCLIC_POSITION 
PBL_CIA402_MODE_CYCLIC_VELOCITY 
PBL_CIA402_MODE_CYCLIC_TORQUE 

◆ pbl_cia402_state

States of the drive.

Enumerator
PBL_CIA402_NOT_READY_TO_SWITCH_ON 
PBL_CIA402_SWITCH_ON_DISABLED 
PBL_CIA402_READY_TO_SWITCH_ON 
PBL_CIA402_SWITCHED_ON 
PBL_CIA402_OPERATION_ENABLED 
PBL_CIA402_QUICK_STOP_ACTIVE 
PBL_CIA402_FAULT_REACTION_ACTIVE 
PBL_CIA402_FAULT 

Function Documentation

◆ pbl_cia402_fault()

int pbl_cia402_fault ( struct pbl_cia402 *  drive,
uint16_t  code 
)

Report a fault: the drive goes to fault reaction active, sets the error code (0x603f) and raises an emergency.

Parameters
driveDrive.
codeError code, e.g. 0x2310 for a continuous over-current.
Returns
0, or -EALREADY if the drive is in fault.

◆ pbl_cia402_fault_reaction_done()

void pbl_cia402_fault_reaction_done ( struct pbl_cia402 *  drive)

End the fault reaction: the drive goes to fault, until the master resets it.

Parameters
driveDrive.

◆ pbl_cia402_init()

int pbl_cia402_init ( struct pbl_cia402 *  drive,
struct pbl_canopen *  co,
const struct pbl_cia402_ops *  ops,
void *  arg 
)

Attach a drive to a node, initialized and not started, in switch on disabled.

Parameters
driveDrive.
coNode.
opsCallbacks, or NULL.
argCallback argument.
Returns
0, or -ENOENT if the node's object dictionary has no drive.

◆ pbl_cia402_mode()

enum pbl_cia402_mode pbl_cia402_mode ( struct pbl_cia402 *  drive)

Get the mode of operation of a drive.

Parameters
driveDrive.
Returns
Mode, as the modes of operation display (0x6061) shows it.

◆ pbl_cia402_quick_stop_done()

void pbl_cia402_quick_stop_done ( struct pbl_cia402 *  drive)

End a quick stop: the drive goes to switch on disabled, or stays in quick stop active with quick stop option codes 5 to 8.

Parameters
driveDrive.

◆ pbl_cia402_set_status()

void pbl_cia402_set_status ( struct pbl_cia402 *  drive,
uint16_t  mask,
uint16_t  bits 
)

Set statusword bits the application owns, PBL_CIA402_SW_* ones.

Parameters
driveDrive.
maskBits to change.
bitsTheir values.

◆ pbl_cia402_state()

enum pbl_cia402_state pbl_cia402_state ( struct pbl_cia402 *  drive)

Get the state of a drive.

Parameters
driveDrive.
Returns
State.