Hello,
Was trying to figure out the best way to count the steps in left(+) and right(-) directions on my stepper motor.
Tried a few different things including a count = count + 1 type of variable
as well as For/next loop and while loop...with no luck.
Here is the VBScript in RR:
[code]
'Stepper motor pan on X-axis
cogX = GetVariable("COG_X")
cogBoxSize = GetVariable("COG_BOX_SIZE")
directionX = GetVariable("directionX")
directionX = cogX
directionStep = GetVariable("directionStep")
countStepsLeft = GetStrVariable("countStepsLeft")
countStepsRight = GetStrVariable("countStepsRight")
countSteps = GetVariable("countSteps")
countStepsLeft = 0
countStepsRight = 0
'for the deadzone
if directionX > 146 and directionX < 174 then
directionStep = 0
end if
'turns right
if directionX > 175 then
directionStep = -1
end if
'turns left
if directionX < 145 then
directionStep = 1
end if
SetVariable "directionX", directionX
SetVariable "directionStep", directionStep
SetVariable "countStepsLeft", countStepsLeft
SetVariable "countStepsRight", countStepsRight
SetVariable "COG_BOX_SIZE", cogBoxSize
[/code]
Also attached RR file. program.robo
|
|
Forgot to add the image res.
320x240
Also the serial output to my Arduino sketch:
[code]
//
//
#include <Stepper.h>
// Stepper motor:
const int stepsPerRevolution = 200; /* change this to fit the number of steps per revolution. Default is 200 (@ 1.8degree).
for your motor */
// initialize the stepper library on the motor shield
Stepper myStepper(stepsPerRevolution, 12,13);
// give the stepper motor control pins names:
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;
int directionStep =0;
char incomingData[4] = {0, 0, 0, 0}; // A buffer to store the ASCII value read in from the serial port
int distanceX = 0; // The distance of the object from the center of the screen
int currentStep = 0;
int i = 0; // counter
void setup(){
Serial.begin(9600); // Open the serial port with a 9600 baud rate
//Serial.println("Serial port ready"); // Print on screen
pinMode(pwmA, OUTPUT);
pinMode(pwmB, OUTPUT);
pinMode(brakeA, OUTPUT);
pinMode(brakeB, OUTPUT);
digitalWrite(pwmA, HIGH);
digitalWrite(pwmB, HIGH);
digitalWrite(brakeA, LOW);
digitalWrite(brakeB, LOW);
// set the motor speed (for multiple steps only):
myStepper.setSpeed(14);
}
void loop()
{
myStepper.step(0);
// Wait for data to become available at the serial port
if (Serial.available())
{
// Get the data coming through the serial port and store it in the buffer
while (i < 4){
incomingData[i] = Serial.read(); // Assign the input value to the incomingData buffer
i++; // Increment the counter
}
directionStep = atoi(incomingData); // Convert ASCII to Int
directionStep = constrain(directionStep, -50, 50);
myStepper.step(directionStep);
myStepper.step(0);
//delay(10);
}
i = 0; // Reset the counter
delay(10); // Delay 20ms
}
[/code]
thomas
|
|