![]() |
Bioscara
DALSA's DIY SCARA Robot Arm.
|
Joint firmware. More...
Classes | |
| class | Lowpass |
| Simple discrete IIR lowpass filter. More... | |
| class | MovMax |
| Simple FIR moving maximum filter. More... | |
Enumerations | |
| enum | stp_reg_t { PING = 0x0f , SETUP = 0x10 , SETRPM = 0x11 , GETDRIVERRPM = 0x12 , MOVESTEPS = 0x13 , MOVEANGLE = 0x14 , MOVETOANGLE = 0x15 , GETMOTORSTATE = 0x16 , RUNCOTINOUS = 0x17 , ANGLEMOVED = 0x18 , SETCURRENT = 0x19 , SETHOLDCURRENT = 0x1A , SETMAXACCELERATION = 0x1B , SETMAXDECELERATION = 0x1C , SETMAXVELOCITY = 0x1D , ENABLESTALLGUARD = 0x1E , DISABLESTALLGUARD = 0x1F , CLEARSTALL = 0x20 , SETBRAKEMODE = 0x22 , ENABLEPID = 0x23 , DISABLEPID = 0x24 , ENABLECLOSEDLOOP = 0x25 , DISABLECLOSEDLOOP = 0x26 , SETCONTROLTHRESHOLD = 0x27 , MOVETOEND = 0x28 , STOP = 0x29 , GETPIDERROR = 0x2A , CHECKORIENTATION = 0x2B , GETENCODERRPM = 0x2C , HOME = 0x2D , HOMEOFFSET = 0x2E } |
| register and command definitions More... | |
Functions | |
| template<typename T > | |
| void | readValue (T &val, uint8_t *rxBuf, size_t rx_length) |
| Reads a value from a buffer to a value of the specified type. | |
| template<typename T > | |
| int | writeValue (const T val, uint8_t *txBuf, size_t &tx_length) |
| Writes a value of the specified type to a buffer. | |
| void | blocking_handler (uint8_t reg) |
| Handles commands received via I2C. | |
| void | non_blocking_handler (uint8_t reg) |
| Handles read request received via I2C. | |
| void | set_flags_for_blocking_handler (uint8_t reg) |
| prepare flags to initiate the blocking handling of the received comman. | |
| void | receiveEvent (int n) |
| I2C receive event Handler. | |
| void | requestEvent () |
| I2C request event Handler. | |
| void | setup (void) |
| Setup Peripherals. | |
| void | loop (void) |
| Main loop. | |
| float | stall_threshold (float qd_rad, float offset) |
| computes the speed adaptive threshold. | |
Variables | |
| UstepperS32 | stepper |
| The core UstepperS32 stepper object to control the motor. | |
| uint8_t | reg = 0 |
| uint8_t | blk_reg = 0 |
| uint8_t | rx_buf [MAX_BUFFER] = {0} |
| uint8_t | tx_buf [MAX_BUFFER+RFLAGS_SIZE] = {0} |
| bool | rx_data_ready = 0 |
| size_t | tx_length = 0 |
| size_t | rx_length = 0 |
Joint firmware.
The joint firmware is implemented in the Arduino framework. Initially the setup() function is called and subsequently the loop() function in an infinite loop. The receiveEvent() is executed when a I2C message is received, and the requestEvent() when data is requested. This always happens sequentially because at least always the #state flags are returned to the robot controller
register and command definitions
a register can be read (R) or written (W), each register has a size in bytes. The payload can be split into multiple values or just be a single value. Note that not all functions are implemented.
| void bioscara_joint_firmware::blocking_handler | ( | uint8_t | reg | ) |
Handles commands received via I2C.
The registers handled in this handler are those whose implementation can take time and can thereby not be called directly from the request handler.
| reg | command that should be executed. |
| void bioscara_joint_firmware::loop | ( | void | ) |
Main loop.
Executes the following:
| void bioscara_joint_firmware::non_blocking_handler | ( | uint8_t | reg | ) |
Handles read request received via I2C.
Can be invoked from the I2C ISR since reads from the stepper are non-blocking. Also Handling reads and the subsequent wire.write(), did not work from the main loop.
| reg | command to execute/register to read. |
| void bioscara_joint_firmware::readValue | ( | T & | val, |
| uint8_t * | rxBuf, | ||
| size_t | rx_length | ||
| ) |
Reads a value from a buffer to a value of the specified type.
| val | Reference to output variable |
| rxBuf | Buffer to read value from |
| rx_length | Length of the buffer |
| void bioscara_joint_firmware::receiveEvent | ( | int | n | ) |
I2C receive event Handler.
Reads the content of the received message. Saves the register so it can be used in the main loop. If the master invokes the read() function the message contains only the register byte and no payload. If the master invokes the write() the message has a payload of appropriate size for the command. Every I2C transaction starts with a receive event when the command is sent and is immediatly followed by a request since at minimum the flags need to be transmitted back. This means that the receive handler and request handler are always executed sequentially. The main loop is not executed since both handlers are ISRs. For a read request the message looks like this:
< [REG]
> [TXBUFn]...[TXBUF2][TXBUF1][TXBUF0][FLAGS]
For a command the message looks like this:
< [REG][RXBUFn]...[RXBUF2][RXBUF1][RXBUF0]
> [FLAGS]
The payload is read into the rx_buf, rx_length is set to the payload length.
| n | the number of bytes read from the controller device: MAX_BUFFER |
| void bioscara_joint_firmware::requestEvent | ( | ) |
I2C request event Handler.
Sends the response data to the master. Every transaction begins with a receive event. The request event is always triggered since at a minimum the status flags are returned to the master. Hence this function is only invoked after the receiveEvent() handler has been called. The function calls the non_blocking_handler() which is non-blocking. Since most Ustepper functions are non-blocking as they just read/write registers to the stepper driver/encoder they can be handled directly in the ISR. The non_blocking_handler() populates the tx_buf with relevant data, the current state flags are appended to the tx_buf and then it is send to the master.
| void bioscara_joint_firmware::set_flags_for_blocking_handler | ( | uint8_t | reg | ) |
prepare flags to initiate the blocking handling of the received comman.
Sets the blk_reg to reg, this makes sure that even if a new command is received the blocking hanlder access the latest blocking command. Sets the isBusy flag, to indicate immediatly that the blocking has not been finished. This is if a status request follows immidiatly the command, before the context back to the main loop has happened. Sets the rx_data_ready flag to indicate to the main loop that there is data to read in the blocking handler. Sets the tx_length to 0 because blocking commands can not return a payload.
| void bioscara_joint_firmware::setup | ( | void | ) |
Setup Peripherals.
Setup I2C with the address ADR, and begin Serial for debugging with baudrate 9600. Setup the stepper, perform orientation check to check wiring and disable the stepper again.
| float bioscara_joint_firmware::stall_threshold | ( | float | qd_rad, |
| float | offset | ||
| ) |
computes the speed adaptive threshold.
| qd_rad | speed in rad/s. Should be measured speed because set speed is only available in velocity mode. |
| int bioscara_joint_firmware::writeValue | ( | const T | val, |
| uint8_t * | txBuf, | ||
| size_t & | tx_length | ||
| ) |
Writes a value of the specified type to a buffer.
| val | Reference to input variable |
| txBuf | pointer to tx buffer |
| tx_length | Length of the buffer returne |
| uint8_t bioscara_joint_firmware::blk_reg = 0 |
| uint8_t bioscara_joint_firmware::reg = 0 |
| uint8_t bioscara_joint_firmware::rx_buf[MAX_BUFFER] = {0} |
| bool bioscara_joint_firmware::rx_data_ready = 0 |
| size_t bioscara_joint_firmware::rx_length = 0 |
| UstepperS32 bioscara_joint_firmware::stepper |
The core UstepperS32 stepper object to control the motor.
| uint8_t bioscara_joint_firmware::tx_buf[MAX_BUFFER+RFLAGS_SIZE] = {0} |
| size_t bioscara_joint_firmware::tx_length = 0 |