changeset 3:f8bffeb4f945

Update the PCB and controller code
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Thu, 10 Mar 2016 23:08:15 +0100
parents c694cfc44d91
children d279d961c91b
files controller/controller.ino controller/i2c.h controller/i2c.ino doc/scad/tote.png doc/scad/tote.scad fritzing/pcb-had.fzz fritzing/pcb-had.zip
diffstat 7 files changed, 31 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/controller/controller.ino	Sun Mar 06 22:15:50 2016 +0100
+++ b/controller/controller.ino	Thu Mar 10 23:08:15 2016 +0100
@@ -5,10 +5,10 @@
 
 void setup() {
     servo_setup();
-    i2c_setuo();
+    i2c_setup();
 }
 
 void loop() {
     delay(100);
-    i2c_loop()
+    i2c_loop();
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/controller/i2c.h	Thu Mar 10 23:08:15 2016 +0100
@@ -0,0 +1,2 @@
+void i2c_setup(void);
+void i2c_loop(void);
--- a/controller/i2c.ino	Sun Mar 06 22:15:50 2016 +0100
+++ b/controller/i2c.ino	Thu Mar 10 23:08:15 2016 +0100
@@ -1,16 +1,36 @@
 #include <Wire.h>
+#include "leg.h"
 
 
 const int SLAVE_ADDRESS = 0x09;
+const int MAX_REGS = 16;
+volatile int8_t regs[MAX_REGS] = {};
+volatile uint8_t address;
 
 
 void i2c_setup() {
     Wire.begin(SLAVE_ADDRESS);
-    Wire.onReceive(receiveEvent);
+    Wire.onReceive(receive);
 }
 
-void receiveEvent(int bytes) {
+void receive(int bytes) {
+    address = Wire.read();
+    while (Wire.available()) {
+        regs[address] = Wire.read();
+        ++address;
+        if (address >= MAX_REGS) {
+            return;
+        }
+    }
 }
 
 void i2c_loop() {
+    for (int leg = 0; leg < 3; ++leg) {
+        if (regs[leg * 4]) {
+            move_leg(leg, regs[leg * 4 + 1],
+                          regs[leg * 4 + 2],
+                          regs[leg * 4 + 3]);
+            regs[leg * 4] = 0;
+        }
+    }
 }
Binary file doc/scad/tote.png has changed
--- a/doc/scad/tote.scad	Sun Mar 06 22:15:50 2016 +0100
+++ b/doc/scad/tote.scad	Thu Mar 10 23:08:15 2016 +0100
@@ -3,7 +3,7 @@
 module leg(hip, knee, ankle, explode) {
     SG90_single_horn();
     translate([0, 0, explode]) SG90_horn_screw();
-    translate([0, 0, -explode * 2]) rotate(hip - 50 - 90) {
+    translate([0, 0, -explode * 2]) rotate(hip - 40) {
         rotate(0) SG90();
         translate([18, -22 - explode, -28.75]) rotate([90, 180, 90]) {
             SG90();
@@ -105,16 +105,16 @@
 }
 
 module robot(explode) {
-    translate([20.75, 20.75, -2.1 + explode]) rotate(175) mirror([0, 1, 0]) {
+    translate([20.75, 20.75, -2.1 + explode]) rotate(175) {
         leg(0, 0, 0, explode);
     }
-    translate([-20.75, -20.75, -2.1 + explode]) rotate(-5) mirror([0, 1, 0]) {
+    translate([-20.75, -20.75, -2.1 + explode]) rotate(-5) {
         leg(0, 0, 0, explode);
     }
-    translate([20.75, -20.75, -2.1 + explode]) rotate(-175) {
+    translate([20.75, -20.75, -2.1 + explode]) rotate(-175) mirror([0, 1, 0]) {
         leg(0, 0, 0, explode);
     }
-    translate([-20.75, 20.75, -2.1 + explode]) rotate(5) {
+    translate([-20.75, 20.75, -2.1 + explode]) rotate(5) mirror([0, 1, 0]) {
         leg(0, 0, 0, explode);
     }
     body(explode);
Binary file fritzing/pcb-had.fzz has changed
Binary file fritzing/pcb-had.zip has changed