jjklein – Physical Computing https://courses.ideate.cmu.edu/16-223/f2014 Carnegie Mellon University, IDeATe Fri, 11 Aug 2017 21:41:33 +0000 en-US hourly 1 https://wordpress.org/?v=4.7.28 Autonomous Robot Part 3 – Watchdog https://courses.ideate.cmu.edu/16-223/f2014/autonomous-robot-2c-watchdog/ Tue, 18 Nov 2014 02:37:32 +0000 http://courses.ideate.cmu.edu/physcomp/f14/16-223/?p=2934 Group members: Daniel Hua and Jesse Klein

Introduction

For the third iteration of this project, we focused on giving the robot a more fluid motion, as well as a more well-defined behavior. We moved the sensors farther away from each other in order to get a more noticeble difference between the two sensor readings.

In order to reduce noise in the readings, we average the past samples up to a point, and use those values instead of the raw sensor output. We take the difference between these values to get the average difference between the two sensors. Since we’re averaging past values, there is a noticeable delay in the numbers; it takes a second before moving in front of the sensor before the numbers reflect that change. To counter this, we set the speed of the motor instead of the position directly. To calculate the speed, we take the derivative of the difference, which is then mapped to a motor speed and sent to the Arduino.

The resulting behavior is less predictable than before, but transitions between different states are much smoother in this iteration. Some physical limitations of the motor and gears also contribute to the behavior of the robot.

Video

Technical Notes

The hardware remains largely the same as in the last iteration, but the software has undergone significant change. The data from the sonar sensors is now sent via the Arduino to a Pure Data patch running on a laptop, which interprets it and maps it to motor speed. This data is sent back to the Arduino, which controls the stepper motor with an EasyDriver shield.

IMG_7060

IMG_7021IMG_7041

]]>
Autonomous Robot Part 2 – Watchdog https://courses.ideate.cmu.edu/16-223/f2014/autonomous-robot-part-2-watchdog/ Tue, 04 Nov 2014 03:40:05 +0000 http://courses.ideate.cmu.edu/physcomp/f14/16-223/?p=2511 Group members: Daniel Hua, Jesse Klein

Introduction

Watchdog is an autonomous robot that keeps an eye on its surroundings and shines a light to investigate anything of interest. It uses two ultrasonic rangefinders to monitor nearby objects, scanning back and forth continuously and tracking nearby objects. When it identifies something of interest, it swivels towards its target, locks on, and shines a bright light to illuminate its target.

Video

 

Technical Notes

The top platform of the robot rotates on a slip ring driven by a geared stepper motor, which allows it to rotate without twisting wires. On the top platform, there are two ultrasonic rangefinders that sense distance. These distance values are collected by a Teensy 2.0, then sent to a laptop, which runs a Python program that converts it to behavior. The Python program then sends a signal back to the Teensy, and that signal contains information about the behavior of the  motor and the lamp.

The motor is powered by a 12v stepper motor driver, and the Arduino is powered by the USB port from the laptop. The lamp is powered by 120v AC from the wall, which is switched on and off using a relay. Because the Arduino’s output pins cannot provide enough current current to the relay to switch it on, we add a transistor in between the Arduino and the relay to switch the relay on and off.

circuit diagram

Circuit Diagram

 

IMG_7046IMG_7021IMG_7041IMG_5316

 

 

Code

 Arduino code:

#include <NewPing.h>
#include <AccelStepper.h>

#define TRIGGER_PIN_B 0
#define TRIGGER_PIN_A 2
#define ECHO_PIN_B 1
#define ECHO_PIN_A 3
#define RELAY_PIN 11

#define MAX_DISTANCE 200

NewPing sonarA(TRIGGER_PIN_A, ECHO_PIN_A, MAX_DISTANCE);
NewPing sonarB(TRIGGER_PIN_B, ECHO_PIN_B, MAX_DISTANCE);

AccelStepper stepper(1, 9, 10);

int counter = 0;
int A, B;
int lampTime = 0;

int lastSpeed = 0;

boolean lampOn = false;

int serialSpeed = 400;

void setup() {
stepper.setMaxSpeed(10000);
stepper.setAcceleration(10000);
// stepper.setSpeed(5000);

pinMode(RELAY_PIN, OUTPUT);

Serial.begin(115200);
}

void loop() {
if (counter % 100 == 0) {
A = sonarA.ping() / US_ROUNDTRIP_CM;
B = sonarB.ping() / US_ROUNDTRIP_CM;
int pos = stepper.currentPosition() % 3840;
// if(pos <= 30)
// delay(1000);
// Serial.print(pos);
// Serial.print(“\t”);
Serial.print(A);
Serial.print(“\t”);
Serial.println(B);
}

if (Serial.available()) {
int num = 0;
int sign = 1;
byte digit;
byte incomingByte = Serial.read();
if (incomingByte == ‘-‘) {
sign = -1;
}
else {
digit = incomingByte – ‘0’;

if (digit >= 0 && digit <= 9) {
num = digit;
}
}

while (Serial.available()) {
incomingByte = Serial.read();
digit = incomingByte – ‘0’;
if (digit >= 0 && digit <= 9) {
num *= 10;
num += digit;
}
}

serialSpeed = sign*num;

if(serialSpeed == 0) {
lampOn = true;
lampTime = 0;
}
lastSpeed = serialSpeed;
}

if(lampOn) {
digitalWrite(RELAY_PIN, HIGH);
lampTime++;

if (lampTime > 2000) {
lampOn = false;
}
}
else {
digitalWrite(RELAY_PIN, LOW);
}

stepper.setSpeed(serialSpeed);
stepper.runSpeed();

counter++;
}

Python code:

import serial
import random
ser = serial.Serial(‘/dev/tty.usbmodem12341’, 9600)

while 1 :
input = ser.readline()
values = input.split(“\t”, 2)
s1 = long(values[0])
s2 = long(values[1][:len(values[1])])
print s1, s2
if (s1 – s2 > 0) :
#move clockwise
ser.write(“-750”)
# print “clockwise”
elif (s1 – s2 < 0) :
#move counter clockwise
ser.write(“750”)
elif (s1 < 30):
ser.write(“0”)
else :
ser.write(“100”)

]]>