Robot Aided Drafting
Loading...
Searching...
No Matches
Macros | Functions | Variables
motors.c File Reference

Low‑level motion engine for stepper‑driven SCARA joints. More...

#include "joint_inputs.h"
#include "motors.h"
#include "pins.h"
#include "us_sensor.h"
#include "stm32f4xx_hal.h"
#include <math.h>
#include <stdbool.h>

Go to the source code of this file.

Macros

#define STEPS_PER_DEG1   (200.0f * 32.0f / 360.0f)
 
#define STEPS_PER_DEG2   (200.0f * 32.0f / 360.0f)
 
#define MAX_Z_MM   5.0f
 
#define DIR_TO_HOME1   GPIO_PIN_SET
 
#define DIR_TO_HOME2   GPIO_PIN_SET
 
#define HOMING_FREQ_HZ   4000U
 
#define DRAW_FREQ_HZ   2000U
 
#define HOMING_TIMEOUT_MS   3000U
 
#define DRAW_TIMEOUT_MS   3000U
 
#define SWITCH_DEBOUNCE_MS   5U
 
#define SWITCH_STABLE_CNT   3U
 
#define PEN_UP   2000
 
#define PEN_DOWN   1000
 
#define JOINT2_ZERO_DEG   0.00f
 
#define DIR2_EXTEND   GPIO_PIN_RESET
 
#define DIR2_RETRACT   GPIO_PIN_SET
 
#define EN_ACTIVE_HIGH   0
 
#define TIM3_CLOCK_HZ   1000000U
 
#define MAX_PLAN_POINTS   5000 /* hard ceiling on way‑points */
 
#define SPLINE_MAX_SUBDIV   48 /* upper cap on subdivisions/segment */
 
#define SPLINE_RES_DEG   0.05f /* max ∆θ (deg) between samples */
 
#define SPLINE_TENSION   0.75f
 

Functions

void motorsEnable (void)
 Enable outputs on both DRV8825 stepper motor drivers.
 
void motorsDisable (void)
 Disable outputs on both DRV8825 stepper motor drivers.
 
bool motorsHome (void)
 Actuates both stepper motors until robot links engage limit switches.
 
void moveServoPulse (uint32_t us)
 Actuates servo motor to move prismatic end effector.
 
void newsendJointAngles (float theta1, float theta2, int curr_z)
 Actuates Joint 1, Joint 2 and end effector to prescribed positions.
 
bool motorsRunSplinePlan (const GCodeMove *plan, size_t n)
 Implements Catmull-Rom spline pathing for given draw plan.
 
void MOT_TIM3_IRQHandler (void)
 Checks if steps_remaining == 0 for reach stepper motor. If steps_remaining == 0 for either stepper motor, stops timer channel to shut off actuation.
 

Variables

TIM_HandleTypeDef htim1
 
TIM_HandleTypeDef htim3
 

Detailed Description

Low‑level motion engine for stepper‑driven SCARA joints.

Date
2025-06-12
Author
Dylan Featherson, Tomas Franco, Charith Sunku

Definition in file motors.c.

Macro Definition Documentation

◆ DIR2_EXTEND

#define DIR2_EXTEND   GPIO_PIN_RESET

◆ DIR2_RETRACT

#define DIR2_RETRACT   GPIO_PIN_SET

◆ DIR_TO_HOME1

#define DIR_TO_HOME1   GPIO_PIN_SET

◆ DIR_TO_HOME2

#define DIR_TO_HOME2   GPIO_PIN_SET

◆ DRAW_FREQ_HZ

#define DRAW_FREQ_HZ   2000U

◆ DRAW_TIMEOUT_MS

#define DRAW_TIMEOUT_MS   3000U

◆ EN_ACTIVE_HIGH

#define EN_ACTIVE_HIGH   0

◆ HOMING_FREQ_HZ

#define HOMING_FREQ_HZ   4000U

◆ HOMING_TIMEOUT_MS

#define HOMING_TIMEOUT_MS   3000U

◆ JOINT2_ZERO_DEG

#define JOINT2_ZERO_DEG   0.00f

◆ MAX_PLAN_POINTS

#define MAX_PLAN_POINTS   5000 /* hard ceiling on way‑points */

◆ MAX_Z_MM

#define MAX_Z_MM   5.0f

◆ PEN_DOWN

#define PEN_DOWN   1000

◆ PEN_UP

#define PEN_UP   2000

◆ SPLINE_MAX_SUBDIV

#define SPLINE_MAX_SUBDIV   48 /* upper cap on subdivisions/segment */

◆ SPLINE_RES_DEG

#define SPLINE_RES_DEG   0.05f /* max ∆θ (deg) between samples */

◆ SPLINE_TENSION

#define SPLINE_TENSION   0.75f

◆ STEPS_PER_DEG1

#define STEPS_PER_DEG1   (200.0f * 32.0f / 360.0f)

◆ STEPS_PER_DEG2

#define STEPS_PER_DEG2   (200.0f * 32.0f / 360.0f)

◆ SWITCH_DEBOUNCE_MS

#define SWITCH_DEBOUNCE_MS   5U

◆ SWITCH_STABLE_CNT

#define SWITCH_STABLE_CNT   3U

◆ TIM3_CLOCK_HZ

#define TIM3_CLOCK_HZ   1000000U

Function Documentation

◆ MOT_TIM3_IRQHandler()

void MOT_TIM3_IRQHandler ( void )

Checks if steps_remaining == 0 for reach stepper motor. If steps_remaining == 0 for either stepper motor, stops timer channel to shut off actuation.

◆ motorsDisable()

void motorsDisable ( void )

Disable outputs on both DRV8825 stepper motor drivers.

◆ motorsEnable()

void motorsEnable ( void )
inline

Enable outputs on both DRV8825 stepper motor drivers.

Referenced by motorsHome().

◆ motorsHome()

bool motorsHome ( void )

Actuates both stepper motors until robot links engage limit switches.

References motorsEnable(), and moveServoPulse().

◆ motorsRunSplinePlan()

bool motorsRunSplinePlan ( const GCodeMove * plan,
size_t n )

Implements Catmull-Rom spline pathing for given draw plan.

Parameters
planArray of joint anlges for full drawing
nSize of plan

References newsendJointAngles().

◆ moveServoPulse()

void moveServoPulse ( uint32_t us)

Actuates servo motor to move prismatic end effector.

Parameters
us

Referenced by motorsHome(), and newsendJointAngles().

◆ newsendJointAngles()

void newsendJointAngles ( float theta1,
float theta2,
int curr_z )

Actuates Joint 1, Joint 2 and end effector to prescribed positions.

Parameters
theta1Required joint angle for Joint 1
theta2Required joint angle for Joint 2
curr_zRequired z position of end effector

References moveServoPulse().

Referenced by motorsRunSplinePlan().

Variable Documentation

◆ htim1

TIM_HandleTypeDef htim1
extern

◆ htim3

TIM_HandleTypeDef htim3
extern