Tutorial 03 Chronos Watch Controlled Rover

simonmonk edited this page Apr 8, 2013 · 3 revisions

This tutorial shows you how to build on Tutorial 02, to control your rover using the wireless accelerometer feature of the Chronos EZ-430 watch. Raise your hand and the rover starts moving forwards, lower it and it stops, rotate your wrist to the left and the rover turns left, rotate it to the right and the rover turns right!

Watch Bot

Here is a Youtube video of the rover in action: http://youtu.be/T_NB44FhRIo

And here is a video of it on the bench: http://youtu.be/-qHpqYByu_8

If you are not familiar with the Chronos watch, it is a fantastic little gadget, that functions as a digital watch, but also, amongst other things, has an accelerometer and a wireless transceiver. So it comes with a USB dongle that you can plug into your Raspberry Pi and then write a Python program to read acceleration data transmitted from the watch.

Wire up the rover just as you did in Tutorial 02 but instead of the wireless dongle for the keyboard, use the dongle for the watch.

Install and run this program on your Raspberry Pi over SSH (see Tutorial 02).


import time
import serial
import array
from raspirobotboard import *

rr = RaspiRobot()

def startAccessPoint():
    return array.array('B', [0xFF, 0x07, 0x03]).tostring()

def accDataRequest():
    return array.array('B', [0xFF, 0x08, 0x07, 0x00, 0x00, 0x00, 0x00]).tostring()

def twos_comp(val, bits = 8):
  if ((val & (1 << (bits-1))) != 0):
    val = val -(1 << bits)
  return val

ser = serial.Serial('/dev/ttyACM0',115200,timeout=1)

full = 16
half = 12
dead = 20
go_level = 10

while (True):
  accel = ser.read(7)
  x = -twos_comp(ord(accel[0])) # -50 to +50
  y = twos_comp(ord(accel[1]))
  z = twos_comp(ord(accel[2]))
  if x > -dead and x < dead:
	left_duty = full
	right_duty = full
  elif x <= -dead:
	left_duty = full
	right_duty = half
  elif x >= dead:
	left_duty = half
	right_duty = full	

  go = (y < go_level)
  if x == 0 and y == 0 and z == 0:
	go = 0

  #print(str(left_duty * go) + " " + str(right_duty * go) + " " + str(y))

  # rough pwm of left and right channels
  for j in range(1, 100):
    for i in range(1, 16):
	  rr.set_motors((left_duty * go > i), 0, (right_duty * go > i), 0)