Controlor for Humanoid. Walking trajectory generator, sensor reflection etc.

Dependencies:   Adafruit-PWM-Servo-Driver MPU6050 RS300 mbed

Revision:
17:60de3bfdc70b
Parent:
16:e65c192b7ecf
Child:
18:7077bedc37eb
--- a/Motions.cpp	Wed Feb 27 12:32:44 2013 +0000
+++ b/Motions.cpp	Tue Apr 02 04:19:09 2013 +0000
@@ -1,30 +1,28 @@
 #include <iostream>
 #include <string>
-#include "mbed.h"
-#include "CSV.h"
+
 #include "Motions.h"
-#include "Motion.h"
-//#include "SCI.h"
-//#include "PWM.h"
 
-extern uint16_t data[0x2000] __attribute__((section("AHBSRAM1")));
-extern Ticker tick;
+Ticker tick;
 
-bool g_motion_playing = false;
-
-Serial serial(USBTX, USBRX);
-//Serial device(p28, p27);
+//detach may be better to controled from Motions class
 
 Motions::Motions(uint16_t* data)
 {
     pwm = new PWM();
+    //comu = new SCI(p28, p27);
+    
+    comu = new SCI(USBTX, USBRX);
+    
     LocalFileSystem* local = new LocalFileSystem("local");
+    
     read("/local/motion.csv", data);
     set(data);
+    
     playing = false;
     
-    //comu = new SCI(USBTX, USBRX);
-    comu = new SCI(p28, p27);
+    // Motion 0 is Home position
+    setmotion(0);
 }
 
 Motions::~Motions()
@@ -43,12 +41,6 @@
     CSV csv;
     pose_size = new int;
     csv.read(filename, data, &servo_size, &motion_size, pose_size);
-    
-    //serial.printf("readed!\r\n");
-    //serial.printf("servo_size:%d motion_size:%d\r\n", servo_size, motion_size);
-    //for (int i = 0; i < motion_size; ++i) {
-        //serial.printf("motion %d pose_size:%d\r\n", i, pose_size[i]);
-    //}
 }
 
 void Motions::set(uint16_t* data)
@@ -81,16 +73,18 @@
 
 void Motions::setmotion(const int id)
 {
-    if (!g_motion_playing) {
-        inter = new Motion(motions[id], pose_size[id], servo_size, pwm);
-        tick.attach(inter, &Motion::step, TIMESTEP);
-        playing = true;
+    if (!playing) {
+        offline = new Motion(motions[id], pose_size[id], servo_size, pwm, &playing);
+        tick.attach(offline, &Motion::step, TIMESTEP);
+        //online = new OnlineMotion(1.0, TIMESTEP, servo_size, pwm, &playing);
+        //tick.attach(online, &OnlineMotion::step, TIMESTEP);
     }
 }
 
 void Motions::control()
 {
-    char head = comu->getheader();
+    setmotion(1);
+    /*char head = comu->getheader();
     if (head == 'A') {
         int id = comu->getid();
         if (checkid(id)) {
@@ -100,6 +94,6 @@
         int id = comu->getid();
         uint16_t val = comu->getservoval();
         pwm->SetDuty(id, (uint32_t)val);
-    }
+    }*/
     
 }
\ No newline at end of file