19 changed files with 478 additions and 92 deletions
-
2components/tmc/basic/tmc_ic_interface.hpp
-
8components/tmc/ic/ztmc4361A.hpp
-
4components/tmc/ic/ztmc5130.hpp
-
74components/xy_robot_ctrl_module/xy_robot_ctrl_module.cpp
-
54components/xy_robot_ctrl_module/xy_robot_ctrl_module.hpp
-
73components/zcancmder/cmd.hpp
-
50components/zcancmder/cmd/basic_bean.hpp
-
49components/zcancmder/cmd/basic_cmd.hpp
-
61components/zcancmder/cmd/c1006_module_cmd.hpp
-
8components/zcancmder/cmd/cmd.hpp
-
4components/zcancmder/zcanreceiver.hpp
-
28components/zcancmder_module/zcan_basic_order_module.cpp
-
24components/zcancmder_module/zcan_basic_order_module.hpp
-
10components/zcancmder_module/zcan_xy_robot_module.cpp
-
14components/zcancmder_module/zcan_xy_robot_module.hpp
-
1os/zos.hpp
-
3os/zos_thread.hpp
-
70os/zthread.cpp
-
33os/zthread.hpp
@ -0,0 +1,74 @@ |
|||
#include "xy_robot_ctrl_module.hpp"
|
|||
using namespace iflytop; |
|||
using namespace std; |
|||
void XYRobotCtrlModule::initialize(IStepperMotor* stepM1, //
|
|||
IStepperMotor* stepM2, //
|
|||
ZGPIO* Xgpio, //
|
|||
ZGPIO* Ygpio, //
|
|||
float distanceK) { |
|||
m_stepM1 = stepM1; |
|||
m_stepM2 = stepM2; |
|||
m_Xgpio = Xgpio; |
|||
m_Ygpio = Ygpio; |
|||
m_distanceK = distanceK; |
|||
m_thread.init("XYRobotCtrlModule", 1024, osPriorityNormal); |
|||
} |
|||
|
|||
void XYRobotCtrlModule::enable(bool venable) { |
|||
m_stepM1->enable(venable); |
|||
m_stepM2->enable(venable); |
|||
} |
|||
|
|||
int32_t XYRobotCtrlModule::getMotor1Pos() { return m_stepM1->getXACTUAL() * m_distanceK; } |
|||
int32_t XYRobotCtrlModule::getMotor2Pos() { return m_stepM2->getXACTUAL() * m_distanceK; } |
|||
|
|||
void XYRobotCtrlModule::getNowPos(int32_t& x, int32_t& y) { |
|||
// y=M1+M2;
|
|||
// X=m1-m2;
|
|||
x = getMotor1Pos() - getMotor2Pos(); |
|||
y = getMotor1Pos() + getMotor2Pos(); |
|||
} |
|||
|
|||
void XYRobotCtrlModule::move_to(int32_t x, int32_t y) { |
|||
/**
|
|||
* @brief |
|||
*/ |
|||
m_thread.stop(); |
|||
m_thread.start([this]() { |
|||
// 计算dpos1,dpos2
|
|||
|
|||
/**
|
|||
* @brief 等待电机运行到到位 |
|||
*/ |
|||
}); |
|||
} |
|||
void XYRobotCtrlModule::move_by(int32_t dx, int32_t dy) {} |
|||
void XYRobotCtrlModule::move_to_zero() {} |
|||
void XYRobotCtrlModule::move_to_with_calibrate(int32_t x, int32_t y) {} |
|||
void XYRobotCtrlModule::stop() {} |
|||
|
|||
uint8_t XYRobotCtrlModule::read_status() {} |
|||
|
|||
void XYRobotCtrlModule::set_acc(int32_t acc) {} |
|||
void XYRobotCtrlModule::set_dec(int32_t dec) {} |
|||
|
|||
void XYRobotCtrlModule::loop() {} |
|||
|
|||
void XYRobotCtrlModule::forward_kinematics(int32_t m1pos, int32_t m2pos, int32_t& x, int32_t& y) { |
|||
#if 1
|
|||
x = m1pos - m2pos; |
|||
y = m1pos + m2pos; |
|||
#else
|
|||
x = m1pos + m2pos; |
|||
y = m1pos - m2pos; |
|||
#endif
|
|||
} |
|||
void XYRobotCtrlModule::inverse_kinematics(int32_t x, int32_t y, int32_t& m1pos, int32_t& m2pos) { |
|||
#if 1
|
|||
m1pos = (x + y) / 2; |
|||
m2pos = (y - x) / 2; |
|||
#else
|
|||
m1pos = (x - y) / 2; |
|||
m2pos = (x + y) / 2; |
|||
#endif
|
|||
} |
@ -0,0 +1,54 @@ |
|||
#pragma once
|
|||
//
|
|||
#include "sdk/os/zos.hpp"
|
|||
#include "sdk\components\tmc\basic\tmc_ic_interface.hpp"
|
|||
#include "sdk\components\zcancmder\zcanreceiver.hpp"
|
|||
|
|||
namespace iflytop { |
|||
class XYRobotCtrlModule { |
|||
IStepperMotor* m_stepM1; |
|||
IStepperMotor* m_stepM2; |
|||
|
|||
ZGPIO* m_Xgpio; |
|||
ZGPIO* m_Ygpio; |
|||
|
|||
ZThread m_thread; |
|||
|
|||
float m_distanceK = 1.0f; |
|||
|
|||
int m_x = 0; |
|||
int m_y = 0; |
|||
|
|||
public: |
|||
void initialize(IStepperMotor* stepM1, //
|
|||
IStepperMotor* stepM2, //
|
|||
ZGPIO* Xgpio, //
|
|||
ZGPIO* Ygpio, //
|
|||
float distanceK); |
|||
|
|||
void enable(bool venable); |
|||
|
|||
void move_to(int32_t x, int32_t y); |
|||
void move_by(int32_t dx, int32_t dy); |
|||
void move_to_zero(); |
|||
void move_to_with_calibrate(int32_t x, int32_t y); |
|||
void stop(); |
|||
|
|||
uint8_t read_status(); |
|||
|
|||
void set_acc(int32_t acc); |
|||
void set_dec(int32_t dec); |
|||
|
|||
void loop(); |
|||
|
|||
private: |
|||
int32_t getMotor1Pos(); |
|||
int32_t getMotor2Pos(); |
|||
|
|||
void getNowPos(int32_t& x, int32_t& y); |
|||
void computeTargetMotorPos(); |
|||
|
|||
void forward_kinematics(int32_t m1pos, int32_t m2pos, int32_t& x, int32_t& y); |
|||
void inverse_kinematics(int32_t x, int32_t y, int32_t& m1pos, int32_t& m2pos); |
|||
}; |
|||
} // namespace iflytop
|
@ -1,73 +0,0 @@ |
|||
#pragma once
|
|||
#include "sdk/os/zos.hpp"
|
|||
|
|||
namespace iflytop { |
|||
namespace zcr { |
|||
|
|||
typedef struct { |
|||
uint16_t packetindex; |
|||
uint16_t cmdid; |
|||
uint8_t subcmdid; |
|||
uint8_t packetType; |
|||
uint8_t data[]; |
|||
} Cmdheader_t; |
|||
|
|||
typedef enum { |
|||
kpt_cmd = 0, |
|||
kpt_ack = 1, |
|||
kpt_error_ack = 2, |
|||
kpt_status_report = 3, |
|||
} PacketType_t; |
|||
|
|||
typedef enum { |
|||
kcmd_ping = 0, |
|||
kcmd_read_io = 1, |
|||
kcmd_set_io = 2, |
|||
kcmd_readadc_raw = 3, |
|||
|
|||
kcmd_m211887_operation = 1000, // 维萨拉臭氧传感器
|
|||
kcmd_read_presure_sensor = 1001, // 压力传感器
|
|||
kcmd_triple_warning_light_ctl = 1002, // 三色警示灯控制
|
|||
kcmd_high_power_electrical_ctl = 1003, // 大功率电源控制
|
|||
kcmd_peristaltic_pump_ctl = 1004, // 液泵控制
|
|||
kcmd_read_huacheng_pressure_sensor = 1005, // 华诚压力传感器
|
|||
} CmdID_t; |
|||
} // namespace zcr
|
|||
} // namespace iflytop
|
|||
|
|||
typedef struct { |
|||
uint8_t boardid; |
|||
} kcmd_ping_t; |
|||
|
|||
typedef struct { |
|||
uint8_t boardid; |
|||
} kcmd_ping_ack_t; |
|||
|
|||
typedef struct { |
|||
uint8_t ioid; |
|||
} kcmd_read_io_t; |
|||
|
|||
typedef struct { |
|||
uint8_t ioid; |
|||
uint8_t val; |
|||
} kcmd_read_io_ack_t; |
|||
|
|||
typedef struct { |
|||
uint8_t ioid; |
|||
uint8_t val; |
|||
} kcmd_set_io_t; |
|||
|
|||
typedef struct { |
|||
uint8_t ioid; |
|||
uint8_t val; |
|||
} kcmd_set_io_ack_t; |
|||
|
|||
typedef struct { |
|||
uint8_t sensorid; |
|||
} kcmd_readadc_raw_t; |
|||
|
|||
typedef struct { |
|||
uint8_t sensorid; |
|||
uint8_t __p; // padding
|
|||
int32_t val; |
|||
} kcmd_readadc_raw_ack_t; |
@ -0,0 +1,50 @@ |
|||
#pragma once
|
|||
#include "sdk/os/zos.hpp"
|
|||
/*******************************************************************************
|
|||
* MARCO * |
|||
*******************************************************************************/ |
|||
#define SUBPACKET(name, ...) \
|
|||
struct { \ |
|||
__VA_ARGS__ \ |
|||
} name |
|||
|
|||
/*******************************************************************************
|
|||
* STRUCT * |
|||
*******************************************************************************/ |
|||
namespace iflytop { |
|||
namespace zcr { |
|||
#pragma pack(push, 1)
|
|||
typedef struct { |
|||
uint16_t packetindex; |
|||
uint16_t cmdid; |
|||
uint8_t subcmdid; |
|||
uint8_t packetType; |
|||
uint8_t data[]; |
|||
} Cmdheader_t; |
|||
#pragma pack(pop)
|
|||
|
|||
typedef enum { |
|||
kpt_cmd = 0, |
|||
kpt_ack = 1, |
|||
kpt_error_ack = 2, |
|||
kpt_cmd_exec_status_report = 3, |
|||
} PacketType_t; |
|||
|
|||
typedef enum { |
|||
kcmd_ping = 0, |
|||
kcmd_read_io = 1, |
|||
kcmd_set_io = 2, |
|||
kcmd_readadc_raw = 3, |
|||
|
|||
kcmd_m211887_operation = 1000, // 维萨拉臭氧传感器
|
|||
kcmd_read_presure_sensor = 1001, // 压力传感器
|
|||
kcmd_triple_warning_light_ctl = 1002, // 三色警示灯控制
|
|||
kcmd_high_power_electrical_ctl = 1003, // 大功率电源控制
|
|||
kcmd_peristaltic_pump_ctl = 1004, // 液泵控制
|
|||
kcmd_read_huacheng_pressure_sensor = 1005, // 华诚压力传感器
|
|||
|
|||
kc1006_xy_robot_ctrl = 1006, // XY机器人控制
|
|||
} CmdID_t; |
|||
|
|||
} // namespace zcr
|
|||
} // namespace iflytop
|
@ -0,0 +1,49 @@ |
|||
#pragma once
|
|||
#include "basic_bean.hpp"
|
|||
#include "sdk/os/zos.hpp"
|
|||
|
|||
namespace iflytop { |
|||
namespace zcr { |
|||
|
|||
#pragma pack(push, 1)
|
|||
typedef struct { |
|||
uint8_t boardid; |
|||
} kcmd_ping_t; |
|||
|
|||
typedef struct { |
|||
uint8_t boardid; |
|||
} kcmd_ping_ack_t; |
|||
|
|||
typedef struct { |
|||
uint8_t ioid; |
|||
} kcmd_read_io_t; |
|||
|
|||
typedef struct { |
|||
uint8_t ioid; |
|||
uint8_t val; |
|||
} kcmd_read_io_ack_t; |
|||
|
|||
typedef struct { |
|||
uint8_t ioid; |
|||
uint8_t val; |
|||
} kcmd_set_io_t; |
|||
|
|||
typedef struct { |
|||
uint8_t ioid; |
|||
uint8_t val; |
|||
} kcmd_set_io_ack_t; |
|||
|
|||
typedef struct { |
|||
uint8_t sensorid; |
|||
} kcmd_readadc_raw_t; |
|||
|
|||
typedef struct { |
|||
uint8_t sensorid; |
|||
uint8_t __p; // padding
|
|||
int32_t val; |
|||
} kcmd_readadc_raw_ack_t; |
|||
|
|||
#pragma pack(pop)
|
|||
|
|||
} // namespace zcr
|
|||
} // namespace iflytop
|
@ -0,0 +1,61 @@ |
|||
#pragma once
|
|||
#include "basic_bean.hpp"
|
|||
#include "sdk/os/zos.hpp"
|
|||
|
|||
namespace iflytop { |
|||
namespace zcr { |
|||
|
|||
/*******************************************************************************
|
|||
* 1006 * |
|||
*******************************************************************************/ |
|||
|
|||
typedef enum { |
|||
kc000_enable = 0, |
|||
kc001_stop = 1, |
|||
kc002_move_to_zero = 2, |
|||
kc003_move_to_with_calibrate = 3, |
|||
kc004_move_to = 4, |
|||
kc005_move_by = 5, |
|||
kc050_read_status = 50, |
|||
kc100_set_acc = 100, |
|||
kc101_set_dec = 101, |
|||
kc102_set_speed = 102, |
|||
} kc1006_xy_robot_ctrl_subcmd_t; |
|||
|
|||
#pragma pack(push, 1)
|
|||
typedef struct { |
|||
uint8_t sensorid; |
|||
union { |
|||
SUBPACKET(cxxx, uint8_t _pad;); |
|||
SUBPACKET(c000_enable, uint8_t enable;); |
|||
SUBPACKET(c003_move_to_with_calibrate, uint8_t _pad; int32_t x; int32_t y;); |
|||
SUBPACKET(c004_move_to, uint8_t _pad; int32_t x; int32_t y;); |
|||
SUBPACKET(c005_move_by, uint8_t _pad; int32_t dx; int32_t dy;); |
|||
SUBPACKET(c100_set_acc, uint8_t _pad; int32_t acc;); |
|||
SUBPACKET(c101_set_dec, uint8_t _pad; int32_t dec;); |
|||
SUBPACKET(c102_set_speed, uint8_t _pad; int32_t speed;); |
|||
} cmd; |
|||
} kc1006_xy_robot_ctrl_t; |
|||
|
|||
typedef struct { |
|||
uint8_t sensorid; |
|||
union { |
|||
SUBPACKET(cxxx, uint8_t _pad;); |
|||
SUBPACKET(c050_read_pos, uint8_t module_statu; int32_t x; int32_t y;); |
|||
} ack; |
|||
} kc1006_xy_robot_ctrl_ack_t; |
|||
|
|||
typedef struct { |
|||
uint8_t sensorid; |
|||
union { |
|||
SUBPACKET(c002_move_to_zero, uint8_t _pad;); |
|||
SUBPACKET(c003_move_to_with_calibrate, uint8_t _pad;); |
|||
SUBPACKET(c004_move_to, uint8_t _pad;); |
|||
SUBPACKET(c005_move_by, uint8_t _pad;); |
|||
} report; |
|||
} kc1006_xy_robot_ctrl_exec_status_report_t; |
|||
|
|||
#pragma pack(pop)
|
|||
|
|||
} // namespace zcr
|
|||
} // namespace iflytop
|
@ -0,0 +1,8 @@ |
|||
#pragma once
|
|||
#include "sdk/os/zos.hpp"
|
|||
//
|
|||
#include "basic_bean.hpp"
|
|||
//
|
|||
#include "basic_cmd.hpp"
|
|||
#include "c1006_module_cmd.hpp"
|
|||
|
@ -0,0 +1,10 @@ |
|||
#include "zcan_xy_robot_module.hpp"
|
|||
using namespace iflytop; |
|||
|
|||
void ZCANXYRobotCtrlModule::initialize(ZCanCmder* cancmder, int id) { |
|||
m_cancmder = cancmder; |
|||
m_id = id; |
|||
} |
|||
void ZCANXYRobotCtrlModule::onRceivePacket(CanPacketRxBuffer* rxcmd) { |
|||
|
|||
} |
@ -0,0 +1,14 @@ |
|||
#pragma once
|
|||
#include "sdk\components\xy_robot_ctrl_module\xy_robot_ctrl_module.hpp"
|
|||
#include "sdk\components\zcancmder\zcanreceiver.hpp"
|
|||
|
|||
namespace iflytop { |
|||
class ZCANXYRobotCtrlModule : public ZCanCmderListener { |
|||
ZCanCmder* m_cancmder = nullptr; |
|||
int m_id = 0; |
|||
|
|||
public: |
|||
void initialize(ZCanCmder* cancmder, int id); |
|||
virtual void onRceivePacket(CanPacketRxBuffer* rxcmd); |
|||
}; |
|||
} // namespace iflytop
|
@ -0,0 +1,70 @@ |
|||
#include "zthread.hpp"
|
|||
|
|||
#include "zoslogger.hpp"
|
|||
using namespace iflytop; |
|||
using namespace std; |
|||
|
|||
static void zosthread_default_task(void const *argument) { |
|||
ZThread *thread = (ZThread *)argument; |
|||
ZASSERT(thread); |
|||
|
|||
while (true) { |
|||
thread->m_threadisworking = false; |
|||
|
|||
// µÈ´ýtaskworking
|
|||
xEventGroupWaitBits(thread->m_zthreadstartworkevent, 0x01, pdTRUE, pdTRUE, portMAX_DELAY); |
|||
thread->m_threadisworking = true; |
|||
thread->m_taskfunction(); |
|||
} |
|||
}; |
|||
|
|||
void ZThread::init(const char *threadname, int stack_size, osPriority priority) { |
|||
int r_task_create = 0; |
|||
ZASSERT(threadname); |
|||
|
|||
m_lock = xSemaphoreCreateMutex(); |
|||
ZASSERT(m_lock); |
|||
|
|||
m_stacksize = stack_size; |
|||
m_uxPriority = osPriorityNormal; |
|||
m_taskfunction = nullptr; |
|||
m_zthreadstartworkevent = xEventGroupCreate(); |
|||
m_name = threadname; |
|||
|
|||
osThreadDef(zosthread_default_task, zosthread_default_task, m_uxPriority, 0, m_stacksize); |
|||
m_defaultTaskHandle = osThreadCreate(osThread(zosthread_default_task), this); |
|||
ZASSERT(m_defaultTaskHandle != NULL); |
|||
} |
|||
void ZThread::start(zosthread_cb_t cb) { |
|||
m_taskfunction = cb; |
|||
|
|||
ZASSERT(m_taskfunction); |
|||
xSemaphoreTake(m_lock, portMAX_DELAY); |
|||
xEventGroupSetBits(m_zthreadstartworkevent, 0x01); |
|||
while (m_threadisworking != true) { |
|||
vTaskDelay(1); |
|||
} |
|||
xSemaphoreGive(m_lock); |
|||
} |
|||
|
|||
void ZThread::stop() { |
|||
xSemaphoreTake(m_lock, portMAX_DELAY); |
|||
m_expect_stop = true; |
|||
while (m_threadisworking) { |
|||
xTaskNotifyGive(m_defaultTaskHandle); |
|||
vTaskDelay(1); |
|||
} |
|||
m_expect_stop = false; |
|||
xSemaphoreGive(m_lock); |
|||
} |
|||
|
|||
bool ZThread::isExpectStop() { return m_expect_stop; } |
|||
void ZThread::sleep(uint32_t ms) { ulTaskNotifyTake(pdFALSE, pdMS_TO_TICKS(ms)); } |
|||
void ZThread::wake() { |
|||
BaseType_t state; |
|||
if (xPortIsInsideInterrupt()) { |
|||
vTaskNotifyGiveFromISR(m_defaultTaskHandle, &state); |
|||
} else { |
|||
xTaskNotifyGive(m_defaultTaskHandle); |
|||
} |
|||
} |
@ -0,0 +1,33 @@ |
|||
#pragma once
|
|||
#include "osbasic_h.hpp"
|
|||
namespace iflytop { |
|||
|
|||
typedef function<void()> zosthread_cb_t; |
|||
|
|||
class ZThread { |
|||
public: |
|||
const char* m_name; |
|||
size_t m_stacksize; |
|||
osPriority m_uxPriority; |
|||
|
|||
bool m_threadisworking; |
|||
bool m_expect_stop; |
|||
|
|||
zosthread_cb_t m_taskfunction; |
|||
EventGroupHandle_t m_zthreadstartworkevent; |
|||
|
|||
osThreadId m_defaultTaskHandle; |
|||
|
|||
SemaphoreHandle_t m_lock; |
|||
|
|||
public: |
|||
void init(const char* threadname, int stack_size = 1024, osPriority priority = osPriorityNormal); |
|||
void start(zosthread_cb_t cb); |
|||
void stop(); |
|||
|
|||
bool isExpectStop(); |
|||
void sleep(uint32_t ms); |
|||
void wake(); |
|||
}; |
|||
|
|||
} // namespace iflytop
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue