Open Innovation (T3)

Video

Zongxi Huang
1 / 1

Term 1 final code

Zongxi Huang

/*
* Attach an Adafruit Motor Shield to the Arduino Uno/Mega.
* In addition to powering the RC Receiver (with GND and 5V), connect
* one of the RC Receiver's signal pins to the Arduino's digital pin 2.
* The duration of the high RC pulse will be used to control a motor
* attached to Motor Shield motor port 1.
*
* Author: David Wang, NuVu Studio
*/
#include <RCPulseIn.h>
#include <EnableInterrupt.h>


#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMSbot(0x61); // Rightmost jumper closed
Adafruit_MotorShield AFMStop(0x60); // Default address, no jumpers

// On the top shield, connect two steppers, each with 200 steps
Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(200, 1);
Adafruit_StepperMotor *myStepper3 = AFMStop.getStepper(200, 2);

// On the bottom shield connect a stepper to port M3/M4 with 200 steps
//Adafruit_StepperMotor *myStepper1 = AFMSbot.getStepper(200, 2);
// And a DC Motor to port M1
Adafruit_DCMotor *myMotor1 = AFMStop.getMotor(1);


int val = 3;
// define an interrupt for digital pin 2.
// that will need to read an RC pulse train.
defineRC(val);


void setup() {
//while (!Serial);
Serial.begin(9600);           // set up Serial library at 9600 bps
// setup the RC interrupt for digital pin 2.
// (You need to use "defineRC(pin)" for each pin, see above.)
setupRC(val);

//AFMSbot.begin(); // Start the bottom shield
AFMStop.begin(); // Start the top shield
myStepper3->setSpeed(10);  // 10 rpm
myStepper2->setSpeed(10);  // 10 rpm

myStepper3->step(12, BACKWARD, MICROSTEP);
delay(500);
myStepper2->step(23, BACKWARD, MICROSTEP);

// turn on the DC motor
//myMotor1->setSpeed(5);
//myMotor1->run(RELEASE);
}

int i;

void loop() {
//myMotor1->run(FORWARD);

// Use the function "readRC(pinNumber)" to read the duration  
// of the high voltage pulse to digital pin 2.
// (You need to use "defineRC(pin)" and "setupRC(pin)" for each pin, see above.)
Serial.print(readRC(val));
Serial.println();
int SM = deadbandMap(readRC(val),1000,200,2000,-255,0,255);

if(SM>10){
//myStepper3->step(12, FORWARD, DOUBLE);
myStepper3->step(17, FORWARD, MICROSTEP);

delay(100);

for (i=0; i<16; i++) {
//myStepper2->setSpeed(1000);
//myStepper3->setSpeed(1000);
//myMotor1->setSpeed(i);  
//myStepper1->onestep(FORWARD, INTERLEAVE);
myStepper2->onestep(FORWARD, DOUBLE);
myStepper3->onestep(FORWARD, DOUBLE);
//myStepper2->onestep(FORWARD, MICROSTEP);
//myStepper3->onestep(FORWARD, MICROSTEP);
delay(100);
}

//myStepper2->step(15, FORWARD, DOUBLE);
myStepper2->step(15, FORWARD, MICROSTEP);

delay(100);

/////////////

//myStepper3->step(12, BACKWARD, DOUBLE);
myStepper3->step(17, BACKWARD, MICROSTEP);

delay(100);

for (i=16; i!=0; i--) {
//myStepper2->setSpeed(1000);
//myStepper3->setSpeed(i);
//myMotor1->setSpeed(i);  
//myStepper1->onestep(BACKWARD, INTERLEAVE);
myStepper2->onestep(BACKWARD, DOUBLE);
myStepper3->onestep(BACKWARD, DOUBLE);
//myStepper2->onestep(BACKWARD, MICROSTEP);
//myStepper3->onestep(BACKWARD, MICROSTEP);
delay(100);
}
//myStepper2->step(15, BACKWARD, DOUBLE);
myStepper2->step(15, BACKWARD, MICROSTEP);

delay(100);

//myMotor1->run(BACKWARD);

}
else if(SM<-10){
//myStepper3->step(12, FORWARD, DOUBLE);
myStepper3->step(20, FORWARD, MICROSTEP);

delay(100);

for (i=0; i<18; i++) {
//myStepper2->setSpeed(1000);
//myStepper3->setSpeed(1000);
//myMotor1->setSpeed(i);  
//myStepper1->onestep(FORWARD, INTERLEAVE);
myStepper2->onestep(FORWARD, DOUBLE);
myStepper3->onestep(FORWARD, DOUBLE);
//myStepper2->onestep(FORWARD, MICROSTEP);
//myStepper3->onestep(FORWARD, MICROSTEP);
delay(100);
}

//myStepper2->step(15, FORWARD, DOUBLE);
myStepper2->step(35, FORWARD, MICROSTEP);

delay(100);

/////////////

//myStepper3->step(12, BACKWARD, DOUBLE);
myStepper3->step(20, BACKWARD, MICROSTEP);

delay(100);

for (i=18; i!=0; i--) {
//myStepper2->setSpeed(1000);
//myStepper3->setSpeed(i);
//myMotor1->setSpeed(i);  
//myStepper1->onestep(BACKWARD, INTERLEAVE);
myStepper2->onestep(BACKWARD, DOUBLE);
myStepper3->onestep(BACKWARD, DOUBLE);
//myStepper2->onestep(BACKWARD, MICROSTEP);
//myStepper3->onestep(BACKWARD, MICROSTEP);
delay(100);
}
//myStepper2->step(15, BACKWARD, DOUBLE);
myStepper2->step(35, BACKWARD, MICROSTEP);

delay(100);

//myMotor1->run(BACKWARD);
}
else {
myStepper2->release();
myStepper3->release();
}
}







FInal Presentation

Zongxi Huang
1 / 20

12/07/2018: Prototype finalized

Zongxi Huang
1 / 5

Today, I worked on finalizing the first phase of my project. First, I made simple adjustment in the code to correct mistakes I found during my testing yesterday. I also made a number of improvements, such as reducing the length of that the leg has to travel in order to complete one walking motion. In addition, I included a void_setup function that allows the leg to get into the walking position when it is first connected to power. 

Then I attempted to find ways to solve the power issue with the stepper motors. Due to the fact that I have not yet figure out how to more power to the motors, I decided to use a gearbox to improve their performance. However, the gearboxes proved to be very large and occupy most of the motor shaft length I need to mount the leg. As such I need to lengthen the motor shaft length, which would allow me to put the gearbox on the back of the motor and keep my current leg setup.

Overall, I believe that the core objectives of my project for this mod have been achieved. However, if time allows it, I would include a potentiometer into the arduino setup to control the different modes of the leg (ie. jumping, climbing stairs or normal walking)

12/06/2018: Code found

Zongxi Huang
1 / 4

12/05/2018: FURTHER EXPERIMENTATION WITH CODING

Zongxi Huang
1 / 3

During today's class, I made further improvements on the code for controlling the stepper motors. I tried to make each steps of the stepper motor smaller (i.e. 2 instead of 5) to create a smoother motion of the leg. Still, even with this method, the leg movement was still very fragmented and I fear that the choppiness of the movement may affect the effectiveness of the leg at walking (only one of the two motors move at any given time). My first response was to try to modify the "accel_multiStepper" code to fit my setup. However, my attempts to do so failed, and I decided to make more research on how to make the motors move simultaneously. While doing so, the new stepper drivers arrived. At the same time, I found a tutorial that could control the two motors to move in sync. In light of this new discovery, I decided to first setup the A4899 driver for testing. However, due to time constraint, I was unable to begin testing. 

Tomorrow, I plan on beginning testing with the A4899 drivers. If I manage to make them work, then the first phase of my project would be essentially completed.

1 / 2

Today, I started working on adjusting the code to create the movement of the leg. At first, I separated each leg motion into 4 lines of code. However, when I ran the code in the Arduino, I found that due to the block nature of the lines of code, the first motor had to complete its motion before the second one could move. This was not ideal for my leg setup, as it required a coordination of the two legs moving simultaneously. I tried to use another code where I could control the two motors at the same time, but due to time constraints (A-team meet), I deemed that I would not have enough time to figure it out. Instead, I decided to command the motors to move smaller steps one after another. This way, the motors would not come in conflict with one another and I managed to make the current code work. However, during my testing, I ran into another issue. Though the stepper motors worked fine while the is placed on the table, the leg upper leg refused to move when placed on the test rig. It seemed that the motor cannot handle the weight of the leg and it would get stuck whenever it tries to lift itself. 

Tomorrow, I plan on making further testing of the leg and attempt to use the new code as well. I also plan on making research on how to solve the power issue for the legs.

12/03/2018: Stepper motor control solved

Zongxi Huang
1 / 4
D0E0F263-909F-44A1-8D0C-4E799FDEA441.MOV

In today's class, I successfully overcame the issue with controlling the stepper motors. At first, I tried to figure the problem using the code Luis gave me. Despite my efforts, I made little progress. I tried to combine elements of the new coding with a simpler example I used earlier. However, my decision to do so backfired as the motors ceased to move completely and showed no signs of moving after I imported the allegedly improved code. 

My unsuccessful attempt compelled me to look for other solutions. Looking into the studio's electronics inventory, I discovered the only TB6600 driver available to me. After finding a reliable tutorial on Youtube on how to use it to control stepper motors, I decided to attempt to discard the motor shield temporarily and incorporate the driver into my Arduino setup. Though I followed all of the instructions, I was still unable to control the stepper motors.  However, just as I was about to discard the driver, I remembered that there was always the possibility that I had wired up the motor incorrectly. As such, I swapped the position of the wires from the negative port to the positive port. In doing so, I corrected the problem of conflicting current direction within the stepper motor and I was able to control the motors to create a back and forth swinging motion. 

Using this progress, I moved on to create a code that could control the stepper motor using the motor shield. When this attempt was successful, I decided to try to control 2 motors at the same time. After some experimentation and research, I was able to control two stepper motors simultaneously. Unfortunately, due to a lack of time, I was unable to make further progress today. 

Tomorrow, I plan on creating a code that would control the motion of the leg, which I plan on completing this week. 

11/30/2018: Test rig

Zongxi Huang
1 / 7

Today, I built the test rig used to experiment with the different motions of the leg. At first, I wanted to build a structure with four support beams. However, I wanted to keep it as simple as possible, so I decided to go with a three leg support platform. Next, I had to figure out the height at which the leg would be hung. While I wanted to allow the leg to walk, I decided to place it higher because I needed to create the walking motion first. I could then make the ground level taller or driller another whole at a lower point. 

After completing the test rig, I tried to reinforce the structure holding the motors. I wanted a material that would be strong enough to not crack but thin enough to fit and light enough to not increase the weight. I found that the thin transparent plastic sheet fitted many of the qualities that I had been looking for. However, when I cut out the pieces and fitted it to the motors, I found that the material was too soft and flimsy. In the end, I deemed that this addition was not absolutely necessary and I scrapped the idea.

At the end of the day, I looked at what Luis sent me about the Arduino code used to control the motor. Due to time constraint, I did not have time to complete the analysis. I intend to complete it during the weekend. Next week, I plan on working on the code and the movement of the legs. I hope to finish the coding part of my project before pencils down.

11/29/2018: Complete prototype

Zongxi Huang
1 / 15

Today, I worked on constructing the complete prototype leg of my robot. I began by trying to figure out a way to extend the motor shaft long enough to reach the supporting structure placed on the opposite side of the stepper motors. My first idea was to buy a motor shaft adaptor, but this option was expensive and I would have to wait until the order arrived. Furthermore, I would need to re print one of the linkages to adjust to the increased diameter of the shaft adapter. 

My next idea was to screw a second motor handle wheels to the one already used to drive the upper leg and link it to the supporting sturcture with a short screw. While this option would increase the weight of the leg, I decided to use it because the materials used were abundant and I did not have to wait for new orders. Once the decision was made, I put myself to work on extending the shafts of both stepper motors.

During the process, I faced a number of challenges. For instance, i had to widen the screw holes to fit the screws that were used to link the two hand wheels together. In another’s case, I had to change the height of the lock nut in order for the screw to fit into the hand wheel. After a whole period dedicated to this task, I managed to solve all the issues and I succeeded in extending the motor shaft.

I also worked on reinforcing the support structure. While I initially tried to use a 3D printed piece to link the support structure to the main body of the robot, I decided to use acrylic instead, as it was simpler and took much less time to make. 

Next class, I plan on studying what Mr. Luis has sent me. I also plan on working on a testing rig, which I will be using on exhibition day.