You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
140 lines
5.4 KiB
140 lines
5.4 KiB
#include <stddef.h>
|
|
#include <stdio.h>
|
|
|
|
#include "sdk/os/zos.hpp"
|
|
#include "sdk\components\tmc\ic\ztmc4361A.hpp"
|
|
#include "sdk\components\xy_robot_ctrl_module\xy_robot_ctrl_module.hpp"
|
|
#include "sdk\components\zcancmder\zcanreceiver.hpp"
|
|
#include "sdk\components\zcancmder_module\zcan_basic_order_module.hpp"
|
|
#include "sdk\components\zcancmder_module\zcan_xy_robot_module.hpp"
|
|
|
|
#define TAG "main"
|
|
using namespace iflytop;
|
|
using namespace std;
|
|
|
|
extern void umain();
|
|
extern "C" {
|
|
void StartDefaultTask(void const* argument) { umain(); }
|
|
}
|
|
#define TMC_MOTOR_SPI hspi1
|
|
|
|
static TMC4361A motora;
|
|
static TMC4361A motorb;
|
|
static ZCanCmder zcanCmder;
|
|
static ZCanBasicOrderModule zcanBasicOrderModule;
|
|
// static ZCANXYRobotCtrlModule zcanXYRobotCtrlModule;
|
|
static XYRobotCtrlModule xyRobotCtrlModule;
|
|
|
|
void umain() {
|
|
chip_cfg_t chipcfg;
|
|
chipcfg.us_dleay_tim = &DELAY_US_TIMER;
|
|
chipcfg.tim_irq_scheduler_tim = &TIM_IRQ_SCHEDULER_TIMER;
|
|
chipcfg.huart = &DEBUG_UART;
|
|
chipcfg.debuglight = DEBUG_LIGHT_GPIO;
|
|
|
|
chip_init(&chipcfg);
|
|
|
|
zos_cfg_t zoscfg;
|
|
zos_init(&zoscfg);
|
|
|
|
osDelay(1000);
|
|
|
|
{
|
|
TMC4361A::cfg_t cfg = {
|
|
.spi = &TMC_MOTOR_SPI, //
|
|
.csgpio = TMC_MOTOR1_SPI_SELECT1_IO, //
|
|
.resetPin = TMC_MOTOR1_nRESET_IO, //
|
|
.fREEZEPin = TMC_MOTOR1_nFREEZE_IO, //
|
|
.ennPin = PinNull, //
|
|
.driverIC_ennPin = TMC_MOTOR1_SUB_IC_ENN_IO, //
|
|
.driverIC_resetPin = PinNull, //
|
|
};
|
|
motora.initialize(&cfg);
|
|
motora.setMotorShaft(false);
|
|
ZLOGI(TAG, "motora initialize TMC4361A:%x DriverIC:%x", motora.readICVersion(), motora.readSubICVersion());
|
|
}
|
|
|
|
{
|
|
TMC4361A::cfg_t cfg = {
|
|
.spi = &TMC_MOTOR_SPI, //
|
|
.csgpio = TMC_MOTOR2_SPI_SELECT1_IO, //
|
|
.resetPin = TMC_MOTOR2_nRESET_IO, //
|
|
.fREEZEPin = TMC_MOTOR2_nFREEZE_IO, //
|
|
.ennPin = PinNull, //
|
|
.driverIC_ennPin = TMC_MOTOR2_SUB_IC_ENN_IO, //
|
|
.driverIC_resetPin = PinNull, //
|
|
};
|
|
motorb.initialize(&cfg);
|
|
motorb.setMotorShaft(false);
|
|
ZLOGI(TAG, "motorb initialize TMC4361A:%x DriverIC:%x", motorb.readICVersion(), motorb.readSubICVersion());
|
|
}
|
|
|
|
motora.setAcceleration(300000);
|
|
motora.setDeceleration(300000);
|
|
motora.setIHOLD_IRUN(0, 2, 10);
|
|
|
|
motorb.setAcceleration(300000);
|
|
motorb.setDeceleration(300000);
|
|
motorb.setIHOLD_IRUN(0, 2, 10);
|
|
|
|
motora.rotate(0);
|
|
motorb.rotate(0);
|
|
auto zcanCmder_cfg = zcanCmder.createCFG(DEVICE_ID);
|
|
zcanCmder.init(zcanCmder_cfg);
|
|
|
|
/*******************************************************************************
|
|
* zcanBasicOrderModule *
|
|
*******************************************************************************/
|
|
zcanBasicOrderModule.initialize(&zcanCmder);
|
|
zcanBasicOrderModule.reg_set_io(1, [](bool val) { ZLOGI(TAG, "write io 1:%d", val); });
|
|
zcanBasicOrderModule.reg_read_io(1, []() {
|
|
ZLOGI(TAG, "read io 1");
|
|
return 1;
|
|
});
|
|
zcanBasicOrderModule.reg_read_adc(1, []() {
|
|
ZLOGI(TAG, "read adc 1");
|
|
return 123;
|
|
});
|
|
|
|
|
|
/*******************************************************************************
|
|
* zcanXYRobotCtrlModule *
|
|
*******************************************************************************/
|
|
ZGPIO input[8];
|
|
input[0].initAsInput(ARM_SENSOR1_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
|
|
input[1].initAsInput(ARM_SENSOR2_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
|
|
input[2].initAsInput(ARM_SENSOR3_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
|
|
input[3].initAsInput(ARM_SENSOR4_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
|
|
input[4].initAsInput(ARM_SENSOR5_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
|
|
input[5].initAsInput(ARM_SENSOR6_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
|
|
input[6].initAsInput(ARM_SENSOR7_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
|
|
input[7].initAsInput(ARM_SENSOR8_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
|
|
|
|
xyRobotCtrlModule.initialize(&motora, &motorb, &input[6], &input[7], 1.0f);
|
|
xyRobotCtrlModule.set_speed(1000000);
|
|
xyRobotCtrlModule.set_acc(3000000);
|
|
xyRobotCtrlModule.set_dec(3000000);
|
|
xyRobotCtrlModule.set_zero_robottype(xyRobotCtrlModule.corexy);
|
|
xyRobotCtrlModule.set_shaft(false, false);
|
|
// zcanXYRobotCtrlModule.initialize(&zcanCmder, 1, &xyRobotCtrlModule);
|
|
|
|
// ARM_SENSOR1_GPIO.initAsInput(STM32_GPIO::kInput_risingAndFallingIrq, true);
|
|
// ARM_SENSOR2_GPIO.initAsInput(STM32_GPIO::kInput_risingAndFallingIrq, true);
|
|
// ARM_SENSOR3_GPIO.initAsInput();
|
|
// ARM_SENSOR4_GPIO.initAsInput();
|
|
// ARM_SENSOR5_GPIO.initAsInput();
|
|
// ARM_SENSOR6_GPIO.initAsInput();
|
|
// ARM_SENSOR7_GPIO.initAsInput(STM32_GPIO::kInput_risingAndFallingIrq, true);
|
|
// ARM_SENSOR8_GPIO.initAsInput(STM32_GPIO::kInput_risingAndFallingIrq, true);
|
|
|
|
while (true) {
|
|
OSDefaultSchduler::getInstance()->loop();
|
|
zcanCmder.loop();
|
|
// zcanCmder.sendPacket(data, 4);
|
|
#if 0
|
|
osDelay(100);
|
|
ZLOGI(TAG, "input:%d %d %d %d %d %d %d %d", //
|
|
input[0].getState(), input[1].getState(), input[2].getState(), input[3].getState(), input[4].getState(), input[5].getState(), input[6].getState(), input[7].getState());
|
|
#endif
|
|
}
|
|
}
|