#include #include #include #include #include #include #include #include #include #include #include #include #warning code uses old leg numbering! void move_to(struct bot_double*, struct bot_double*, int); void demo(); int get_time(); static struct bot_double startup_position = { {0,0,0}, // body offset {0,0,0}, // world position {0,0,0}, // body rotation { { // leg 0 { 80, 40, 0}, // base offset {200,120,10}, // end effector position { 0, 0, 0} // leg angles },{ // leg 1 { 0, 60, 0}, { 0,200,10}, { 0, 0, 0}, // leg angles },{ {-80, 40, 0}, {-200,120,10}, { 0, 0, 0} // leg angles },{ { 80,-40, 0}, {200,-120,10}, { 0, 0, 0} // leg angles },{ { 0,-60, 0}, {0,-200,10}, { 0, 0, 0} // leg angles },{ {-80,-40, 0}, {-200,-120,10}, { 0, 0, 0} // leg angles }} }; static struct bot_double idle_position = { {0,0,0}, // body offset {0,0,0}, // world position {0,0,0}, // body rotation { { // leg 0 { 80, 40, 0}, // base offset {150,120,120}, // end effector position { 0, 0, 0} // leg angles },{ // leg 1 { 0, 60, 0}, { 0,160,120}, { 0, 0, 0}, // leg angles },{ {-80, 40, 0}, // leg 2 {-150,120,120}, { 0, 0, 0} // leg angles },{ { 80,-40, 0}, // leg 3 {150,-120,120}, { 0, 0, 0} // leg angles },{ { 0,-60, 0}, {0,-160,120}, { 0, 0, 0} // leg angles },{ {-80,-40, 0}, {-150,-120,120}, { 0, 0, 0} // leg angles }} }; static struct bot_double current_position; static struct bot_double target_position; int main(int argc, char **argv) { int i,j; int frame; uint32_t time; printf("welcome.\n"); spi_open(0,33000000); for(i=0;iposition.x+frame*(target_position->position.x-current_position->position.x)/num_frames; frame_position.position.y=current_position->position.y+frame*(target_position->position.y-current_position->position.y)/num_frames; frame_position.position.z=current_position->position.z+frame*(target_position->position.z-current_position->position.z)/num_frames; frame_position.orientation.rx=current_position->orientation.rx+frame*(target_position->orientation.rx-current_position->orientation.rx)/num_frames; frame_position.orientation.ry=current_position->orientation.ry+frame*(target_position->orientation.ry-current_position->orientation.ry)/num_frames; frame_position.orientation.rz=current_position->orientation.rz+frame*(target_position->orientation.rz-current_position->orientation.rz)/num_frames; for(leg=0;legleg[leg].position.x+frame*(target_position->leg[leg].position.x-current_position->leg[leg].position.x)/num_frames; frame_position.leg[leg].position.y=current_position->leg[leg].position.y+frame*(target_position->leg[leg].position.y-current_position->leg[leg].position.y)/num_frames; frame_position.leg[leg].position.z=current_position->leg[leg].position.z+frame*(target_position->leg[leg].position.z-current_position->leg[leg].position.z)/num_frames; } ik_double(&frame_position); for(i=0;i20000) { printf("frame %d delay %d\n",frame,frame_end-frame_start); } while(frame_end-frame_start<20000) { // delay.tv_sec=0; // delay.tv_nsec=(frame_end-frame_start)*1000; // nanosleep(&delay,NULL); frame_end=get_time(); } spi_update_servos(servo); } memcpy(current_position,target_position,sizeof(struct bot_double)); } void move_to_parabolic(struct bot_double *current_position, struct bot_double *target_position, int num_frames, double dx, double dy, double dz, double a, int leg_mask) { struct bot_double frame_position; int frame; int frame_start, frame_end; int leg,i,j; double t,d; memcpy(&frame_position,current_position,sizeof(struct bot_double)); for(frame=1;frame<=num_frames;frame++) { frame_start=get_time(); t=2.0*frame/num_frames-1.0; d=a-(a*t*t); frame_position.position.x=current_position->position.x+frame*(target_position->position.x-current_position->position.x)/num_frames; frame_position.position.y=current_position->position.y+frame*(target_position->position.y-current_position->position.y)/num_frames; frame_position.position.z=current_position->position.z+frame*(target_position->position.z-current_position->position.z)/num_frames; frame_position.orientation.rx=current_position->orientation.rx+frame*(target_position->orientation.rx-current_position->orientation.rx)/num_frames; frame_position.orientation.ry=current_position->orientation.ry+frame*(target_position->orientation.ry-current_position->orientation.ry)/num_frames; frame_position.orientation.rz=current_position->orientation.rz+frame*(target_position->orientation.rz-current_position->orientation.rz)/num_frames; for(leg=0;legleg[leg].position.x+frame*(target_position->leg[leg].position.x-current_position->leg[leg].position.x)/num_frames; frame_position.leg[leg].position.y=current_position->leg[leg].position.y+frame*(target_position->leg[leg].position.y-current_position->leg[leg].position.y)/num_frames; frame_position.leg[leg].position.z=current_position->leg[leg].position.z+frame*(target_position->leg[leg].position.z-current_position->leg[leg].position.z)/num_frames; } else { frame_position.leg[leg].position.x=dx*d + current_position->leg[leg].position.x + frame*(target_position->leg[leg].position.x - current_position->leg[leg].position.x)/num_frames; frame_position.leg[leg].position.y=dy*d + current_position->leg[leg].position.y + frame*(target_position->leg[leg].position.y - current_position->leg[leg].position.y)/num_frames; frame_position.leg[leg].position.z=dz*d + current_position->leg[leg].position.z + frame*(target_position->leg[leg].position.z - current_position->leg[leg].position.z)/num_frames; } } ik_double(&frame_position); for(i=0;i20000) { printf("frame %d delay %d\n",frame,frame_end-frame_start); } while(frame_end-frame_start<20000) { // delay.tv_sec=0; // delay.tv_nsec=(frame_end-frame_start)*1000; // nanosleep(&delay,NULL); frame_end=get_time(); } spi_update_servos(servo); } memcpy(current_position,target_position,sizeof(struct bot_double)); } void walk(double dx, double dy, double alpha, int frames, int mode) { int leg_mask; int i; double step_height=30; struct bot_double start_position; memcpy(&target_position, ¤t_position,sizeof(struct bot_double)); memcpy(&start_position,¤t_position,sizeof(struct bot_double)); leg_mask=0; for(i=0;i=0;i--) { target_position.position.z=10*i; if(i%2) { target_position.position.y=20; } else { target_position.position.y=-20; } move_to(¤t_position,&target_position,25); } target_position.position.y=0; move_to(¤t_position,&target_position,25); // lift middle legs target_position.leg[1].position.z-=80; target_position.leg[1].position.y+=20; target_position.leg[4].position.z-=80; target_position.leg[4].position.y-=20; move_to(¤t_position,&target_position,100); target_position.leg[1].position.y+=80; target_position.leg[4].position.y-=80; move_to(¤t_position,&target_position,100); target_position.position.z+=30; move_to(¤t_position,&target_position,25); target_position.position.z-=60; move_to(¤t_position,&target_position,50); target_position.position.z+=30; move_to(¤t_position,&target_position,25); target_position.leg[1].position.y-=80; target_position.leg[4].position.y+=80; move_to(¤t_position,&target_position,100); memcpy(&target_position,&idle_position,sizeof(struct bot_double)); move_to(¤t_position,&target_position,50); /* walk(50,50,-15*91,25,0); walk(50,50,-15*91,25,0); walk(-50,-50,15*91,25,0); walk(-50,-50,15*91,25,0); walk(50,-50,15*91,25,0); walk(50,-50,15*91,25,0); walk(-50,50,-15*91,25,0); walk(-50,50,-15*91,25,0); */ // lean back and wave target_position.position.x=-40; move_to(¤t_position,&target_position,25); sleep(1); target_position.leg[0].position.x=180; target_position.leg[0].position.y=150; target_position.leg[0].position.z=-120; target_position.leg[3].position.x=180; target_position.leg[3].position.y=-150; target_position.leg[3].position.z=-120; move_to(¤t_position,&target_position,50); for(i=0;i<3;i++) { target_position.leg[0].position.x+=20; target_position.leg[0].position.y-=60; target_position.leg[3].position.x+=20; target_position.leg[3].position.y+=60; move_to(¤t_position,&target_position,12); target_position.leg[0].position.y+=60; target_position.leg[0].position.x-=20; target_position.leg[3].position.y-=60; target_position.leg[3].position.x-=20; move_to(¤t_position,&target_position,12); } sleep(1); memcpy(&target_position,&idle_position,sizeof(struct bot_double)); target_position.position.x=-40; move_to(¤t_position,&target_position,50); target_position.position.x=0; move_to(¤t_position,&target_position,25); target_position.position.z=100; move_to(¤t_position,&target_position,50); for(i=0;i