1 /**
2 * header file for the stepper motor driver
3 **/
4
5 #ifndef MOTOR_CONTROLLER_H
6 #define MOTOR_CONTROLLER_H
7
8 #undef SIMULATION
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <unistd.h>
13 #include <string.h>
14 #include <fcntl.h>
15 #include <sys/stat.h>
16 #include <termios.h>
17 #include <errno.h>
18 #include "sim_motor.h"
19 #include "libmisc/misc.h"
20 #include <math.h>
21 #include <sys/time.h>
22
23 #define CONFIG_FILE "configure"
24 #define NIMS_MOTOR_STATUS_DEVICE "/dev/motor/status"
25
26 #define num_motor 2 // number of motors that are connected to the controller
27
28 // our motor controller can control up to 3 motors at the same time
29 // we are using two motors in this case - one on the motor side, the other on the pulley side
30 // we fixed their id to be 0 and 1
31 #define MOTOR_ID 1
32 #define PULLEY_ID 0
33 #define THICKNESS -0.2
34 // motor delay is inversly protional to its rotation speed
35 // here we fix it at 40
36
37 #define DEFAULT_MOTOR_DELAY 80
38 #define PI 3.1415926
39 #define OUTPUT_FILE "report.txt"
40 #define MOTOR_DELAY DEFAULT_MOTOR_DELAY
41
42 #define MAX_POINTS 200 // declare number of points that need to move in the 2-D plane
43 #define NUM_STEPS_PER_REVOLUTION 400 // fix 200 steps or 400 half steps per revolution
44
45 typedef enum {
46 ERROR = -1,
47 IDLE = 0,
48 ACTIVE,
49 HOLD,
50 SUCCESS,
51 NO_NEED_TO_MOVE
52 } MOTOR_STATUS;
53
54 // structure that includes status for each motor
55 typedef struct {
56 char motor_id;
57 MOTOR_STATUS status;
58 int c_position;
59 int d_position;
60 int flag;
61 int velocity;
62 int max_delay;
63 int min_delay;
64 int num_steps;
65 } MOTOR_INFO;
66
67 MOTOR_STATUS motor_move(int motorID, int distance, int velocity, int fd, int * set_speed_flag, int * go_flag, MOTOR_INFO *motor_info);
68 MOTOR_STATUS motor_move2(int motorID1, int distance1, int motorID2, int distance2, int velocity, int fd, int * set_speed_flag, int * go_flag, int * MOTOR_SPEED, MOTOR_INFO *motor_info);
69
70 MOTOR_STATUS motor_status(int motorID, MOTOR_INFO * motor_info);
71 //MOTOR_STATUS motor_init(int channelID1, int channelID2, int * fd, MOTOR_INFO* motor_info, int * set_speed_flag, int * go_flag );
72
73 // everything is in terms of cm
74 typedef struct {
75 int hor_pulley_dist; // horizontal pulley distance
76 int ver_pulley_height; // vertical pulley height
77 int ver_motor_height; // motor vertical height
78 int motor_seperation; // distance between two motors
79 int motor_pulley_dist; // distance between motor and pulley
80 }ENVIRONMENT_CONSTRAINTS;
81
82
83 typedef struct {
84 int spool_rad; // spool radius
85 int pulley_rad; // pulley radius
86 int cable_thickness; // cable thickness
87 int cable_mass; // mass of the cable, in terms of g
88 int node_mass; // mass of the node, in terms of g
89 }HARDWARE_CONSTRAINTS;
90
91 typedef struct {
92 int num_steps_per_rev; // number of steps per revolution
93 int distance_per_rev; // distance per revolution
94 int max_weight_wo_hold; // maximum weight that the motor can hold without using break
95
96 int node_pulley_dist; // distance between node to pulley
97 int node_motor_dist; // distance between node to motor
98 int c_pos_x; // current position x
99 int c_pos_y; // current position y
100 int d_pos_x; // destination position x
101 int d_pos_y; // destination position y
102 int delta_pulley; // distance that we should move from current to destination
103 int delta_motor; // distance that we should move from current to destination
104
105 float sum_error_motor;
106 float sum_error_pulley;
107 }MOTION_INFO;
108
109 typedef struct motor_global_info {
110 int fd;
111 MOTOR_INFO motor_info[num_motor];
112 int go_flag;
113 int set_speed_flag;
114 int MOTOR_SPEED;
115 ENVIRONMENT_CONSTRAINTS env_cons;
116 HARDWARE_CONSTRAINTS hw_cons;
117 MOTION_INFO motion_info;
118 char serial_port[50];
119 } motor_global_info_t;
120
121 // load in the configuration file and set params accordingly
122 void init_all(motor_global_info_t* m);
123
124 // read config file and store info to our structure
125 int read_config(FILE *fd, ENVIRONMENT_CONSTRAINTS * env_cons, HARDWARE_CONSTRAINTS * hw_cons, MOTION_INFO *motion_info);
126
127 // move one pt to another, distance is in terms of cm
128 int pt_to_pt(int x0, int y0, int x1, int y1, ENVIRONMENT_CONSTRAINTS * env_cons, MOTION_INFO *motion_info, int fd, int * set_speed_flag, int * go_flag, int * MOTOR_SPEED, MOTOR_INFO *motor_info);
129
130 // calculate for pt to pt distance
131 double calc_dist(int x0, int y0, int x1, int y1);
132 int serial_dev_init( motor_global_info_t * m);
133 #endif
134
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.