ProposalBot/Spring/2020

How it should work and why that way?

Author/s: Haydon Chiu

Table of Contents

Initial thoughts before choosing a designated library

In order to program a complex omnidirectional robot, it was necessary to use the Accelstepper library by Airspayce and written by Mike McCauley. The Accelstepper library makes the Proposal bot project incredibly easier by utilizing built-in functions that will support our projects needs. For example, the code shown below, illustrates a rather simple code. It is essentially calling the servo library and having a potentiometer move the servo in a manner relevant to the potentiometer. Some of these steps utilized in this code could had been used for the Proposal bot, but instead, with some research, I found the AccelStepper library created by Mike McCauley as a better alternative due to the more advanced nature of the library.

#include   // add servo library
 
Servo myservo;  // create servo object to control a servo
 
int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin
 
void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}
 
void loop() {
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
}

Accelstepper

Accelstepper was written by Mike McCauley and it makes the Proposal Bot a more efficient bot due to the built-in functions that are pre-defined in the library. The original Omnidirectional project our group’s bot was based off of was using the Accelstepper library as well. In Dejan’s design of his project, he implements functions that will move the bot forward, backward, sideways in both directions, and basically in all moveable directions. His design was perfect for our needs because the way that it moves allows for the bot to easily go in the direction of the movements “Marry Me”. His design involved a remote controller or phone app that would also control the robot and since one of our groups requirement was to use the Arxterra app and control the bot, it could be easily implemented. As one can see in the code below there are functions such as moveForward(), moveSidewaysLeft(), rotateLeft(), and so on. These functions involve a .SetSpeed() function that calls for a speed integer to be put in as a parameter. Our bot will consist of four wheels and can be represented as LeftFrontWheel, LeftBackWheel, RightFrontWheel, and RightBackWheel. These are attached to .SetSpeed() and will all be called in the corresponding functions. For example, moveForward() with a positive parameter on all the wheels would essentially move the bot forward. The moveSidewaysRight() will have the front wheels as a negative motion while the back wheels will be positive, thus allowing for the bot to direct the force to the right. You can see that each function will have the wheels in various positive or negative parameters and that will essentially be the cause of why the bot will move as it should be.

#include 
#include 
#include 
//SoftwareSerial Bluetooth(A8, 38); // Arduino(RX, TX) - HC-05 Bluetooth (TX, RX)
// Define the stepper motors and the pins the will use
AccelStepper LeftBackWheel(1, 42, 43); // (Type:driver, STEP, DIR) - Stepper1
AccelStepper LeftFrontWheel(1, 40, 41); // Stepper2
AccelStepper RightBackWheel(1, 44, 45); // Stepper3
AccelStepper RightFrontWheel(1, 46, 47); // Stepper4
int wheelSpeed = 1500;
void setup() {
// Set initial seed values for the steppers
LeftFrontWheel.setMaxSpeed(3000);
LeftBackWheel.setMaxSpeed(3000);
RightFrontWheel.setMaxSpeed(3000);
RightBackWheel.setMaxSpeed(3000);
delay(20);
// pinMode(led, OUTPUT);
moveForward();
moveSidewaysRight();
}


void loop() {
// put your main code here, to run repeatedly:

}

void moveForward() {
LeftFrontWheel.setSpeed(wheelSpeed);
LeftBackWheel.setSpeed(wheelSpeed);
RightFrontWheel.setSpeed(wheelSpeed);
RightBackWheel.setSpeed(wheelSpeed);
}
void moveBackward() {
LeftFrontWheel.setSpeed(-wheelSpeed);
LeftBackWheel.setSpeed(-wheelSpeed);
RightFrontWheel.setSpeed(-wheelSpeed);
RightBackWheel.setSpeed(-wheelSpeed);
}
void moveSidewaysRight() {
LeftFrontWheel.setSpeed(wheelSpeed);
LeftBackWheel.setSpeed(-wheelSpeed);
RightFrontWheel.setSpeed(-wheelSpeed);
RightBackWheel.setSpeed(wheelSpeed);
}
void moveSidewaysLeft() {
LeftFrontWheel.setSpeed(-wheelSpeed);
LeftBackWheel.setSpeed(wheelSpeed);
RightFrontWheel.setSpeed(wheelSpeed);
RightBackWheel.setSpeed(-wheelSpeed);
}
void rotateLeft() {
LeftFrontWheel.setSpeed(-wheelSpeed);
LeftBackWheel.setSpeed(-wheelSpeed);
RightFrontWheel.setSpeed(wheelSpeed);
RightBackWheel.setSpeed(wheelSpeed);
}
void rotateRight() {
LeftFrontWheel.setSpeed(wheelSpeed);
LeftBackWheel.setSpeed(wheelSpeed);
RightFrontWheel.setSpeed(-wheelSpeed);
RightBackWheel.setSpeed(-wheelSpeed);
}
void moveRightForward() {
LeftFrontWheel.setSpeed(wheelSpeed);
LeftBackWheel.setSpeed(0);
RightFrontWheel.setSpeed(0);
RightBackWheel.setSpeed(wheelSpeed);
}
void moveRightBackward() {
LeftFrontWheel.setSpeed(0);
LeftBackWheel.setSpeed(-wheelSpeed);
RightFrontWheel.setSpeed(-wheelSpeed);
RightBackWheel.setSpeed(0);
}
void moveLeftForward() {
LeftFrontWheel.setSpeed(0);
LeftBackWheel.setSpeed(wheelSpeed);
RightFrontWheel.setSpeed(wheelSpeed);
RightBackWheel.setSpeed(0);
}
void moveLeftBackward() {
LeftFrontWheel.setSpeed(-wheelSpeed);
LeftBackWheel.setSpeed(0);
RightFrontWheel.setSpeed(0);
RightBackWheel.setSpeed(-wheelSpeed);
}
void stopMoving() {
LeftFrontWheel.setSpeed(0);
LeftBackWheel.setSpeed(0);
RightFrontWheel.setSpeed(0);
RightBackWheel.setSpeed(0);
}

}

Getting this Proposal On!

Now that we have the proposal bot moving omnidirectionally. It was time to figure out how it can serve its purpose and autonomously move omnidirectionally to spell “Marry Me”. To do so, some research involving Accelstepper library was needed in order to figure out the best way to possibly implement this process. Some tools or predefined functions that seemed to be possibly useful was moveTo() and runSpeedToPosition(). These two functions go hand in hand and are both needed. The moveTo() function takes a distance as a parameter and it will likely be needed in order move the bot autonomously. I initially would like to plan the to find a perfect distance for the bot to move and use the moveTo() function on all the wheels to move omnidirectionally to draw the intended letters. The runSpeedToPosition() will be called after implementing the moveTo() function because it is basically the initiator to make the bot “run”. However, some more research and debugging will be necessary to figure this issue out, but as of now this will be the outline or thought process of the first iteration of the code.

What next?

Since the concept of moving the bot was deemed possible in the first iteration of V1. It will be interesting to move forward in creating the drawing portion of the bot. Likely, the code will consist of having a pen plotter servo and ring box in the code. Code will likely utilize the servo.h library to just move the ring box and or pen plotter down to the papers. There will obviously be a lot of debugging involved.

References/Resources

  1. https://howtomechatronics.com/projects/arduino-mecanum-wheels-robot/
  2. https://create.arduino.cc/projecthub/Raushancpr/servo-motor-control-with-potentiometer-5d866f
  3. https://drive.google.com/drive/folders/1lABnFTYfihFqZF-4u8HflY_CtCjF_uZU?usp=sharing