simple way to control position | My Assignment Tutor

• A simple way to control position– Used extensively in model aircrafts, boats and carsServosServos• Breakdown of a servo– A DC motor– Gears– Position potentiometer– PCB board (Controller)Picture from Sparkfun : https://learn.sparkfun.com/tutorials/hobby-servo-tutorialServos• Use pulse width modulation (PWM) as input– Recall that : PWM is used to generate analog output– Servo expect a pulse every 20 ms– The angle of the shaft depends on the width of the pulse• 1. 0 ms – > 0 Degree 2.0 ms – > 180 DegreePicture from adafruit : https://learn.adafruit.com/adafruit-arduino-lesson-14-servo-motors/servo-motors• Need an independent power supply• Voltage Regulator (UA7805C 5V Linear Voltage Regulator)– Convert 9V DC to 5V DCTo servo power lineServo wiring9VUA7805CCapacitorGround pinServo SchematicFrom microcontrollerConnections– Brown/black to ground– Red to power– Orange/white to controlServo library• Install ESP32 servo library– Download Zip file: https://github.com/jkb-git/ESP32Servo– Add Library to Arduino IDE• Sketch – > Include Library – > Add .Zip Library• Add Header file in future code :– //Include Library ESP32_Servo– #include Servo library• ESP32 Servo library– servo.attach(pin) or servo.attach(pin, min, max)• Pin is the pin number controlling (GPIO Pins)• min and max have default values: 1000/2000– Arduino: 544/2400– servo.detach()– servo.attached()• Check whether Servo Variable is attached to a pin– servo.write(angle)• Set servo to the given angle ( 0 -180)– servo.writeMicroseconds(u_sec)• Set servo pulse to a given value– servo.read()• return the current settingKnob example• Use the potentiometer to control the angle of the servo– Use A3 to read the potentiometer;– Use 12 to control the servo– Use map for an easy translation;Knob example#include // Controlling a servo position using a potentiometer (variable resistor)// by Michal Rinott // create servo object to control a servoServo myservo;// analog pin used to connect the potentiometerconst int input_pin = A3;// Pin to control the servoconst int servo_pin = 12;// variable to read the value from the analog pinint val;void setup(){// attaches the servo on pin 9 to the servo objectmyservo.attach(servo_pin);}void loop(){// reads the value of the potentiometer (value between 0 and 4095)val = analogRead(input_pin);// scale it to use it with the servo (value between 0 and 180)val = map(val, 0, 4095, 0, 180);// sets the servo position according to the scaled valuemyservo.write(val);// waits for the servo to get theredelay(15);}Stepper motor• Special type of motor moving by steps– Useful for precise motion• Printers, scanners, robots…– High holding torque– But can slip (No feedback mechanism by default)• Best systems use a feedback mechanism• Two kinds– Bipolar ( 4 connections)– Unipolar ( 5,6 connections)• 4 wires– 2 coils controlled independentlyBipolar stepperFrom “Physical Computing” by Dan O’Sullivanhttps://www.youtube.com/watch?v=0qwrnUeSpYQ&t=2099s by DroneBot WorkshopControlling a bipolar stepper• Direct control– Use IO pins to control current flow– Need a special transistor circuit• Use driver modules for a simpler interface– DVR8825 moduleFrom Pololu.comWiring the DVR8825 moduleBe sure to use the isolator!Do not modify circuit while 9V is on!From Pololu.com1213IsolatorESP32 Board Power Boardconst int step_pin = 13;const int direction_pin = 12;// 200 steps for 360 degreeconst int STEPS_PER_TURN = 200;// Adjust the delay for control speedconst int delay_between_step_microsec = 5000;void setup(){Serial.begin(9600);pinMode(step_pin, OUTPUT);pinMode(direction_pin, OUTPUT);}void step(bool forward){// setting the directionif (forward == true){digitalWrite(direction_pin, HIGH);}else{digitalWrite(direction_pin, LOW);}// creating a stepdigitalWrite(step_pin, HIGH);// minimum delay is 1.9usdigitalWrite(step_pin, LOW);}void steps(int number_of_steps){bool move_forward = true;// Establishing the directionif (number_of_steps >= 0){move_forward = true;}else{move_forward = false;number_of_steps = -number_of_steps;}// Generating the stepsfor (int i = 0; i < number_of_steps; i++){step(move_forward);// Delay for proper speeddelayMicroseconds(delay_between_step_microsec);}}void loop(){//your code here}Generating stepsPower setting• Use the trim potentiometer to set the current– Use the minimum current for your application– The servo should feel warm, but not hot– Have us verify your schematic and power setting+ –Test #1• Simple Test– Call steps(50) in the main loop– See your stepper turning smoothly• You should adjust the power down from the default– Call steps(-50) in the main loop– Check if it is coming back at the same positionLidar ArchitectureMeasureSerialDisplay(Processing)Analog WorldControlESP 32 Pictures by Lady Ada , acquired from : https://learn.adafruit.com/adafruit-huzzah32-esp32-feather/pinoutsIR Range sensorSharp GP2Y0A02YK0F• Specifications– Power (red wire): 5V Connect to USB Pin on ESP32– Signal Vo(yellow wire) [email protected] to [email protected]– Approximated by: Lcm= 70/Vo– 6End to End protocol• How to format the data between two applications?– Identifying packets boundaries ( Use period . )– Identifying elements inside a packet ( use comma , )– ESP32 program: sends to the serial port ,.• is the current angle in 1/10 of degree (integer value)– 12 → 1.2 degree• is in mm (integer value)– 10 → 10 mm• How to avoid buffer overrun?– Simple software handshake method• Wait for processing to send you a character after sending dataLidar/SONAR step one• Have the motor scan back and forth between 0 and 160 deg– One step at a time (i.e. 1.8 degree , 200 steps for 360 degrees)Lidar/SONAR step two• Have the motor scan back and forth from 0 to 160 deg– One step at a time (i.e. 1.8 degree)• For each step– Make an analog read– Send to the serial port ,.• is the current angle in 1/10 of degree (integer value)• is in mm (integer value)• For example if you are at 45 deg and you read 80 cm send 450,800.Lidar/SONAR step three• Have the motor scan back and forth from 0 to 160 deg– One step at a time (i.e. 1.8 degree)• For each step– Make an analog read– Send to the serial port ,.• is the current angle in 1/10 of degree (integer value)• is in mm (integer value)• For example if you are at 45 deg and you read 80 cm send 450,800.– Wait for a character before moving to the next step• Use Serial Monitor ( Recall Echo Program)Lidar/SONAR: visualize• Have the motor scan back and forth from 0 to 160 deg– One step at a time (i.e. 1.8 degree)• For each step– Make an analog read– Send to the serial port ,.• is the current angle in 1/10 of degree (integer value)• is in mm (integer value)• For example if you are at 45 deg and you read 80 cm send 450,800.– Wait for a character before moving to the next step• Observe the result on the SONAR Processing programProcessing• A programming language for visual art– Java-based language– Good for data visualization– Download here–• Our visualization program (SONAR)– Download the program here– Change Serial Port Name to yours• Line 36• Program is printing possible values– Only one program can use the serial port at a time– Learn to debug on Processing if needed.

QUALITY: 100% ORIGINAL PAPER – NO PLAGIARISM – CUSTOM PAPER

Leave a Reply

Your email address will not be published. Required fields are marked *