// H-W Robot arm setup -------------------------------------------------------------------------------
// give it a name:
int CH1 = 6;//turn pulse axis 1
int CH2 = 2;//big arm pulse axis 2
int CH3 = 4;//little arm pulse axis 3
int CH4 = 10;//rotate fore arm pulse axis 4
int CH5 = 12;//tool rist axis 5
int CH6 = 8;//tool twist axis 6
int AIR = 33;//tool twist
int GRIP = 32;//tool twist
int buzz = A1;//Alarm buzzer
int CH1dir = 7;//base turn DIR
int CH2dir = 3;//Big Arm Up down Dir
int CH3dir = 5;//little arm Dir
int CH4dir = 24;// Rotate For arm Dir
int CH5dir = 28;//base turn DIR
int CH6dir = 9;//Big Arm Up down Dir
int CH1Count = 0;// Counters
int CH2Count = 0;
int CH3Count = 0;
int CH4Count = 0;
int CH5Count = 0;
int CH6Count = 0;
int accel = 0;
// the setup routine runs once when you press reset:
void setup() {
Serial.begin(9600);
Serial.println("AXIS-1=" + CH1Count);
Serial.println("AXIS-2=" + CH2Count);
Serial.println("AXIS-3=" + CH3Count);
Serial.println("AXIS-4=" + CH4Count);
Serial.println("AXIS-5=" + CH5Count);
Serial.println("AXIS-6=" + CH6Count);
// initialize the digital pin as an output.
pinMode(CH1, OUTPUT);
pinMode(CH1dir, OUTPUT);
pinMode(CH2, OUTPUT);
pinMode(CH2dir, OUTPUT);
pinMode(CH3, OUTPUT);
pinMode(CH3dir, OUTPUT);
pinMode(CH4, OUTPUT);
pinMode(CH4dir, OUTPUT);
pinMode(CH5, OUTPUT);
pinMode(CH5dir, OUTPUT);
pinMode(CH6, OUTPUT);
pinMode(CH6dir, OUTPUT);
pinMode(AIR, OUTPUT);
pinMode(GRIP, OUTPUT);
pinMode(buzz, OUTPUT);
digitalWrite(CH1dir, LOW);
digitalWrite(CH2dir, LOW);
digitalWrite(CH3dir, HIGH);// CHANGE DIR OF CH3 TO up
digitalWrite(CH4dir, LOW);
digitalWrite(CH5dir, LOW);
digitalWrite(CH6dir, LOW);
delay(10);
// END PIN SETUP LIST ---------------------------------------------------------------------------------
// MOVE AXIS OFF STOPS
while (CH3Count < 301)
{
if (CH3Count < 400) {
digitalWrite(CH3, HIGH); // turn the CH1 on (HIGH is the voltage level)
delay(1); // wait for a second
digitalWrite(CH3, LOW); // turn the CH1 off by making the voltage LOW
delay(1);
CH3Count++; // Incress count by one
if ((CH3Count > 50) && (CH3Count < 100)) {
digitalWrite(CH2, HIGH); // turn the CH1 on (HIGH is the voltage level)
delay(1); // wait for a second
digitalWrite(CH2, LOW); // turn the CH1 off by making the voltage LOW
delay(1); // wait for a second
}
else {
CH3Count++; // one tick then brake While loop
}
}
}
//END GET OFF STOPS ZERO COUNTERS----------------------------------------------------------------------
CH1Count = 0;// Counters
CH2Count = 0;
CH3Count = 0;
CH4Count = 0;
CH5Count = 0;
CH6Count = 0;
//debug print current vals as zero
Serial.println("AXIS 1 ZERO");
Serial.println(CH1Count);
Serial.println("AXIS 2");
Serial.println(CH2Count);
Serial.println("AXIS 3");
Serial.println(CH3Count);
Serial.println("AXIS 4");
Serial.println(CH4Count);
Serial.println("AXIS 5");
Serial.println(CH5Count);
Serial.println("AXIS 6");
Serial.println(CH6Count);
//digitalWrite(AIR, HIGH); uncoment after debug to run air
digitalWrite(GRIP, HIGH);
delay(400);
digitalWrite(GRIP, LOW);
delay(1000);
digitalWrite(GRIP, HIGH);
delay(400);
digitalWrite(GRIP, LOW);
delay(1000);
digitalWrite(AIR, LOW);
Serial.println("AXIS 1");
Serial.println(CH1Count);
Serial.println("AXIS 2");
Serial.println(CH2Count);
Serial.println("AXIS 3");
Serial.println(CH3Count);
Serial.println("AXIS 4");
Serial.println(CH4Count);
Serial.println("AXIS 5");
Serial.println(CH5Count);
Serial.println("AXIS 6");
Serial.println(CH6Count);
//SQWEEZ GRIPS
}
void loop (){
accel = 3000; // set accel start of new move
while (CH3Count < 1001)
{
//ACELL -- DE-CELL BLOCK-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=----=
if ((CH3Count < 300) && (CH3Count > 0)){//de-accel
accel--;
accel--;
accel--;
}
else {
if ((CH3Count > 300 ) && (CH3Count < 700)){//QUESTION RANGE
accel = 1000;
}
}
if ((CH3Count > 700) && (CH3Count < 1000)){
accel++;
accel++;
accel++;
}
else {
if ((CH3Count > 300 ) && (CH3Count < 700)) {//QUESTION RANGE
accel = 1000;
}
}
//END ACELL -- DE-CELL BLOCK-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=----=
if (CH3Count < 1000) {
digitalWrite(CH3, HIGH); // turn the CH1 on (HIGH is the voltage level)
delayMicroseconds(accel);// wait for a second;
// accel--;
digitalWrite(CH3, LOW);
delayMicroseconds(accel);
CH3Count++; // incress count one tick
//accel--;
}
else {
CH3Count++; // one tick then brake While loop
}
}// End Of Move<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
//NEW MOVE CH2 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
accel = 3000; // set NEW accel start of new move OR MOVE WILL BE LAST
while (CH2Count < 2501)
{
//ACELL -- DE-CELL BLOCK-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=----=
if ((CH2Count < 200) && (CH2Count > 0)){//de-accel IF POS IS ALL-MOST AT ZERO
accel--;
accel--;
accel--;
}
else {
if ((CH2Count > 400 ) && (CH2Count < 600)){// CENTER RANGE OF CONSTANT SPEED
accel = 1000;
}
}
if ((CH2Count > 600) && (CH2Count < 1000)){ //ACCELL IF POS IS GRATER THEN VAL
accel++;
accel++;
accel++;
}
else {
}
//END ACELL -- DE-CELL BLOCK-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=----= SEET MOTOR MOVMENTS AND POS
if (CH2Count < 1000) {
digitalWrite(CH2, HIGH); // turn the CH1 on (HIGH is the voltage level)
delayMicroseconds(accel);// wait for a second;
// accel--;
digitalWrite(CH2, LOW);
delayMicroseconds(accel);
CH2Count++; // incress count one tick
//accel--;
}
else {
CH2Count++; // one tick then brake While loop
}
// End Of Move
}
//NEW MOVE CH2 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
accel = 3000; // set NEW accel start of new move OR MOVE WILL BE LAST
while (CH2Count < 1001)
{
//ACELL -- DE-CELL BLOCK-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=----=
if ((CH2Count < 200) && (CH2Count > 0)){//de-accel IF POS IS ALL-MOST AT ZERO
accel--;
accel--;
accel--;
}
else {
if ((CH2Count > 400 ) && (CH2Count < 600)){// CENTER RANGE OF CONSTANT SPEED
accel = 1000;
}
}
if ((CH2Count > 600) && (CH2Count < 1000)){ //ACCELL IF POS IS GRATER THEN VAL
accel++;
accel++;
accel++;
}
else {
}
//END ACELL -- DE-CELL BLOCK-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=----= SEET MOTOR MOVMENTS AND POS
if (CH2Count < 1000) {
digitalWrite(CH2, HIGH); // turn the CH1 on (HIGH is the voltage level)
delayMicroseconds(accel);// wait for a second;
// accel--;
digitalWrite(CH2, LOW);
delayMicroseconds(accel);
CH2Count++; // incress count one tick
//accel--;
}
else {
CH2Count++; // one tick then brake While loop
}
// End Of Move
}
// reverse to zero
Is there a question ?
...R
Robin yes ... I'm sorry it was in the subject ..
Trying to Control the beast with less programming .. like single sub loop that i could keep calling out under different conditions ...
like i put this bit together have not reduced the garbage lines out yet ...
accel = 3000; // set accel start of new move
while (CH3Count < 1001)// <<< this forced the conditions to be true
{
//ACELL -- DE-CELL BLOCK-=-=
if ((CH3Count < 300) && (CH3Count > 0)){ //de-accel argument
accel--;// accel being an INT variable called out in the setup as index-able acceleration counter
accel--;// allowing me to use the times thru the loop
accel--;//thus using the returned val as a value for pulse delay
}
else {
if ((CH3Count > 300 ) && (CH3Count < 700)){//then a none accel or de-cell mid RANGE of steps
accel = 1000;
}
}
if ((CH3Count > 700) && (CH3Count < 1000)){
accel++;
accel++;
accel++;
}
else {
// think this else is a repeated logical argument that may not be necessary but does not hurt it
if ((CH3Count > 300 ) && (CH3Count < 700)) {
accel = 1000;
}
}//END ACELL -- DE-CELL BLOCK-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=----=
so what if i could reduce this to a sub loop or some thing that i could call out 3 of the values manual in the ladder of the main progran and then return to this loop for accel and de-accel reasons ...
i looked that the accela stepper a bit that seems to be where i was going with it but it seems like that library is to limited for my 6-axis use
I'm sorry to say I don't understand what your code snippet is trying to do or your description.
Also I have no idea of your programming experience.
If you want to create a responsive program you should not be using WHILE because that blocks the Arduino until it completes. Almost certainly you will want all the motors to be able to move at the same time.
When you use the words "sub loop" do you mean a function? I am a great believer in dividing code into small functions that can be tested separately and called multiple times.
Maybe you would get some ideas from Planning and Implementing a Program
...R
