Junjie Wang
/
humanoid
NYP
Fork of a_NYP_humanoid by
Revision 3:1345f959c490, committed 2018-05-02
- Comitter:
- mr_wang
- Date:
- Wed May 02 07:49:13 2018 +0000
- Parent:
- 2:7d574b1ab3cd
- Commit message:
- ahah
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
servo.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed May 02 03:33:15 2018 +0000 +++ b/main.cpp Wed May 02 07:49:13 2018 +0000 @@ -1,29 +1,31 @@ #include "mbed.h" #include "rtos.h" - +#include "servo.h" #include "accgyro.h" //Serial pc(USBTX, USBRX); DigitalOut led2(LED2); -Thread eventthread; -EventQueue eventqueue; +Thread event_thread; +Thread ACCGYRO_thread; +Thread SERVO_thread; +EventQueue event_queue; int main() { - SERVO_init(); - ACCGYRO_init(); - eventthread.start(callback(&eventqueue, &EventQueue::dispatch_forever)); - //ACCGYRO_thread.start(ACCGYRO_init); + ACCGYRO_thread.start(ACCGYRO_init); + SERVO_thread.start(SERVO_init); + //SERVO_init(); + //event_thread.start(callback(&event_queue, &EventQueue::dispatch_forever)); + //ACCGYRO_init(); + event_thread.start(callback(&event_queue, &EventQueue::dispatch_forever)); //Thread::wait(osWaitForever); - //eventqueue.call_every(1000, SERVO_task); - eventqueue.call_every(1000, ACCGYRO_task); + event_queue.call_every(1000, SERVO_task); + event_queue.call_every(1000, ACCGYRO_task); //q.dispatch(); //eventqueue.call_every(1000,printf,"LSM6DSL [acc/mg]: %6ld\r\n", ACCGYRO_get_gyro_x()); //q.dispatch(); - - while(1) { - eventqueue.call(printf,"LSM6DSL [acc/mg]: %6ld\r\n", ACCGYRO_get_gyro_x()); + //eventqueue.call(printf,"LSM6DSL [acc/mg]: %6ld\r\n", ACCGYRO_get_gyro_x()); led2 = !led2; wait(1); //q.dispatch();
--- a/servo.cpp Wed May 02 03:33:15 2018 +0000 +++ b/servo.cpp Wed May 02 07:49:13 2018 +0000 @@ -1,9 +1,6 @@ #include "mbed.h" #include "rtos.h" -DigitalOut l1(LED1); -DigitalOut l2(LED2); -DigitalOut l3(LED3); -DigitalOut l4(LED4); +DigitalOut led3(LED3); RawSerial motor(PC_4,PC_5); unsigned char tx_buffer[3]; unsigned char tx_buffer_ptr = 0; @@ -18,6 +15,7 @@ void Rx_interrupt(); //EventQueue queue; //Thread t; + void motor_update(unsigned char Id, unsigned short int Position) { unsigned char id,lo,hi; @@ -32,6 +30,7 @@ } void SERVO_task() { + led3 = !led3; for(MotorID=0;MotorID<=1;MotorID++) { motor_update(MotorID,motorcp[MotorID]); @@ -40,7 +39,6 @@ } void SERVO_init() { - l1 = !l1; motor.format(8,Serial::Even,1); motor.baud(115200); rx_buffer_ptr = 0; @@ -48,8 +46,9 @@ motor.attach(&Rx_interrupt, Serial::RxIrq); motor.attach(&Tx_interrupt, Serial::TxIrq); NVIC_EnableIRQ(USART3_IRQn); -// t.start(callback(&queue, &EventQueue::dispatch_forever)); + //t.start(callback(&queue, &EventQueue::dispatch_forever)); //queue.call_every(1000, SERVO_init); +/* while(1) { motorcp[0]=7500; @@ -59,6 +58,7 @@ motorcp[1]=8500; Thread::wait(1000); } +*/ } void Tx_interrupt()