-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
164 lines (113 loc) · 2.14 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* main.cpp
*
* Created on: Dec 25, 2010
* Author: falmarri
*/
#include "WProgram.h"
#include <stdlib.h>
#include "cnccontrol.h"
int buffer[32];
int cur_read;
int commands[8];
int cur_command;
CncControl controller;
int count = 0;
unsigned long mil;
int main(void){
init();
setup();
for (;;){
loop();
}
Serial.println("Main loop returned...");
}
/**
*
* Debug commands:
*
* 0: home
* ret: 1
*
* 1: move_x
* n1: inches integer
* n2: inches decimal
* ret: current x, y
*
* 2: move_y
* n1: inches integer
* n2: inches decimal
* ret: current x, y
*
*
*
*
*
*
*/
int state = LOW;
void loop(){
if (millis() - mil > 3000){
Serial.print("loop ");
Serial.println(state);
if (count < 4){
Serial.println(controller.move_X(1.0));
Serial.println("Moved pos x");
//Serial.println(controller.move_Y(1.0));
//Serial.println("Moved pos y");
count++;
}
else{
Serial.println(controller.move_X(-1.0));
Serial.println("Moved neg x");
//Serial.println(controller.move_Y(-1.0));
//Serial.println("Moved neg y");
count--;
}
digitalWrite(13, state = ~state);
Serial.print("--------------\nCurrent State:\nx: ");
Serial.println(controller.location_x());
Serial.print("y: ");
Serial.print(controller.location_y());
Serial.println("\n--------------");
delay(700);
mil = millis();
}
}
void setup(){
Serial.begin(9600);
controller.set_size(4.0, 4.0);
Serial.print("Controller set. Motor Mask: ");
Serial.println(controller.new_motors(3,4,5,6));
pinMode(13, OUTPUT);
digitalWrite(13, state);
mil = millis();
cur_read = 0;
cur_command= -1;
}
extern "C" void __cxa_pure_virtual()
{
cli();
for (;;);
}
__extension__ typedef int __guard __attribute__((mode (__DI__)));
void * operator new(size_t size)
{
return malloc(size);
}
void operator delete(void * ptr)
{
free(ptr);
}
void * operator new[](size_t size)
{
return malloc(size);
}
void operator delete[](void * ptr)
{
if (ptr)
free(ptr);
}
int __cxa_guard_acquire(__guard *g) {return !*(char *)(g);}
void __cxa_guard_release (__guard *g) {*(char *)g = 1;}
void __cxa_guard_abort (__guard *) {}