Notifications
Clear all

Function arguments

79 Posts
8 Users
12 Likes
803 Views
barrie
(@barrie)
Estimable Member
Joined: 5 months ago
Posts: 86
Topic starter  

@zander @will

this link should work

https://www.dropbox.com/s/2a46f31d17gv86n/yoyo.MOV?dl=0


   
ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 4015
 

@barrie Very nice. Have you replaced your function yoyo with @Wills?

 

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
barrie
(@barrie)
Estimable Member
Joined: 5 months ago
Posts: 86
Topic starter  

@zander My only options are 4K and HD on my iPhone. My last link should now be OK. Please let me know


   
ReplyQuote
Will
 Will
(@will)
Famed Member
Joined: 2 years ago
Posts: 2235
 
Posted by: @barrie

@zander @will

this link should work

https://www.dropbox.com/s/2a46f31d17gv86n/yoyo.MOV?dl=0

IT appears to be exactly the same as the previous version. i was able to view it barrie, that's how I was able to list the steps required to make it available to me.

i am, however, astonished that the software change made no difference at all to the motion of the steppers.

Experience is what you get when you don't get what you want.


   
ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 4015
 

@barrie Yes, it worked, but for future ref get a video file compressor as these things tend to come up on the forum from time to time.

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
barrie
(@barrie)
Estimable Member
Joined: 5 months ago
Posts: 86
Topic starter  

@robotbuilder Yes they do run simultaneously. I used similar code. If you see the video you will see the problem.


   
ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 4015
 

@will My money is on Sir Stepper @Will,

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 4015
 

@barrie I don't know about everyone else but the video tell me nothing. I have no idea what to expect. Have you fixed the code per @Will 's instructions?

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
barrie
(@barrie)
Estimable Member
Joined: 5 months ago
Posts: 86
Topic starter  

@zander Thanks. I'll look for a video compressor.  I tried stuffit but it only shrunk by about 4Meg.


   
ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 4015
 

@barrie Just repost your code.

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 4015
 

@barrie Yes, you cannot compress video like text, it's already compressed. You have to convert it from say 4K  to 640 x 480 or 1024 x 768 if file is small enough.

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
barrie
(@barrie)
Estimable Member
Joined: 5 months ago
Posts: 86
Topic starter  

@zander 

The problem is at case 3: yoyo

see this video https://www.dropbox.com/s/2a46f31d17gv86n/yoyo.MOV?dl=0

 

/*
//Two 28BYJ48 stepper
*/
 
#include 
 
// ************** Constants *************
 const int Rled = 14;
 const int Yled = 15;
 const int Gled = 16;
 const int Bled = 17;
 const int Wled = 18;

// Define step constants
#define FULLSTEP 4
#define HALFSTEP 8
 
// Define Motor Pins (2 Motors used)
 
#define motorPin1  8     // Blue   - 28BYJ48 pin 1
#define motorPin2  9     // Pink   - 28BYJ48 pin 2
#define motorPin3  10    // Yellow - 28BYJ48 pin 3
#define motorPin4  11    // Orange - 28BYJ48 pin 4
                        
                        
#define motorPin5  4     // Blue   - 28BYJ48 pin 1
#define motorPin6  5     // Pink   - 28BYJ48 pin 2
#define motorPin7  6     // Yellow - 28BYJ48 pin 3
#define motorPin8  7     // Orange - 28BYJ48 pin 4
 
// Define two motor objects
// The sequence 1-3-2-4 is required for proper sequencing of 28BYJ48
AccelStepper stepper1(FULLSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
AccelStepper stepper2(FULLSTEP, motorPin5, motorPin7, motorPin6, motorPin8);
 
 const long FullStepsPerRev = 2048*FULLSTEP;

 // ********** Variables **********
long stepsPerRev = 2048;
int revCount = 0; // rotor revolutions 
unsigned long startTime = 0;

//********* Setup ***************
void setup()
{
  // set pins 14, 15, 16, 17, 18 to output pins
  for (int i = 14; i < 19; i++) {
  pinMode (i,OUTPUT);
  }
  Serial.begin (9600);

   // 1 revolution Motor 1
  stepper1.setMaxSpeed(1000.0);
  stepper1.setAcceleration(500.0);
  stepper1.setSpeed(500);
  stepper1.moveTo(2048);
    // 1 revolution Motor 2
  stepper2.setMaxSpeed(1000.0);
  stepper2.setAcceleration(500.0);
  stepper2.setSpeed(200);
  stepper2.moveTo(-2048); 
}
 //****** functions ****
void defaultSettings(){
  // 1 revolution Motor 1 CW
  stepper1.setMaxSpeed(1000.0);
  stepper1.setAcceleration(500.0);
  stepper1.setSpeed(500);
  stepper1.moveTo(2048);
  // 1 revolution Motor 2 CCW
  stepper2.setMaxSpeed(1000.0);
  stepper2.setAcceleration(500.0);
  stepper2.setSpeed(500);
  stepper2.moveTo(-2048); 
}
bool elapsedTime (unsigned long interval)
{ 
  unsigned long currentTime = millis();
  if (startTime = 0)  {startTime = millis();}
  if (currentTime - startTime >= interval) { startTime = 0; return true;}
  else { startTime = currentTime; return false; }
}
//turn LED's off
void alloff() {
for (int i = 14; i < 19; i++){
digitalWrite (i,LOW);
}
}
//turn LED's on
void allon() {
for (int i = 14; i < 19; i++){
digitalWrite (i,HIGH);
}
}
 void setStepper (float mxs,float acc,float spd,long mvt1,long mvt2, int seg) 
 {
  // 1 revolution Motor 1
  stepper1.setMaxSpeed(mxs);
  stepper1.setAcceleration(acc);
  stepper1.setSpeed(spd);
  stepper1.moveTo(mvt1/seg);  
  // 1 revolution Motor 2 
  stepper2.setMaxSpeed(mxs);
  stepper2.setAcceleration(acc);
  stepper2.setSpeed(spd);
  stepper2.moveTo(mvt2/seg); 
}
void newSpeed(int spd){
  stepper1.setSpeed(spd);
  stepper2.setSpeed(spd);  
  } 
// void yoyo(int segment){
//   long target = FullStepsPerRev/segment;
//   stepper1.setCurrentPosition(0);
//   stepper2.setCurrentPosition(0);
//   stepper1.moveTo(target);
//   stepper2.moveTo(-target); 
//   stepper1.runToPosition();
//   stepper2.runToPosition();
// }
void roundAbout(int spd){
stepper1.moveTo(2048);
stepper2.moveTo(-2048);
stepper1.setSpeed(spd);
stepper2.setSpeed(-spd);
}
void yoyo(int segment) {
  long target = FullStepsPerRev / segment;
  stepper1.setCurrentPosition(0);
  stepper2.setCurrentPosition(0);
  stepper1.moveTo(target);
  stepper2.moveTo(-target);
  while (stepper1.distanceToGo()>0) {
     //stepper1.runToPosition();
     //stepper2.runToPosition();
    stepper1.run();
    stepper2.run();
  }
}


 // ************************* Main loop ********************
void loop()
{ 
int x = 0;
int runCount = 0;
 switch (revCount)
 {
    case 2: // slow down
     alloff();
    // mxs,acc,spd,mvt1,mvt2,seg
    setStepper (200.0, 500.0, 200.0, 2048, -2048, 1);
    digitalWrite (Rled,HIGH);
    break; 
    
    case 3: // yoyo +1//8 to -1/8 from current position
    alloff();
    digitalWrite (Yled,HIGH);
     yoyo(8);
    break;

   case 6: // same direction
    alloff(); 
    digitalWrite (Gled,HIGH);
    //roundAbout(400);
    break;

    case 7: // default
     digitalWrite (Bled,HIGH);
     defaultSettings();
    break;

    case 8: 
     digitalWrite (Wled,HIGH);
    break; 

    case 9: //re start cycle
    alloff(); 
    revCount = 0; 
    break;
 }  
  x = revCount;
 while (x == revCount){
   //Change direction at the limits
  if (stepper1.distanceToGo() == 0){
    revCount++;
    stepper1.setCurrentPosition(0);
    stepper2.setCurrentPosition(0);
    stepper1.moveTo(-stepper1.currentPosition());
    stepper2.moveTo(-stepper2.currentPosition());
    stepper1.setCurrentPosition(0);
    stepper2.setCurrentPosition(0);
  } 
  runCount++;
  stepper1.run();
  stepper2.run();
 }
}
This post was modified 4 months ago by barrie

   
ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 4015
 

@barrie If I may suggest, delete all the code not needed to do yoyo and try again. This is a standard debugging step.

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 4015
 

@barrie Another thing to try is to reverse the sign on the MoveTo statements inside yoyo, change the no sign to - and the - to +.

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
barrie
(@barrie)
Estimable Member
Joined: 5 months ago
Posts: 86
Topic starter  

@will yes I replaced my function with yours. It compiled OK but had zero affect. My version works correctly for individual rotors but I need them both to move at the same time. I knew the  "runToPosition" would block that is why I did not put a while loop in the yoyo function.I also tried the ".run" statement but that did not work. "runToPosition" in my original code would be ideal if the two steppers moved at the same time.


   
ReplyQuote
Page 4 / 6