Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 1 Guest are viewing this topic.
It is NOT a good idea to use a DC motor the way you want. What you'll end up with is a stalled motor. Yes, you'll control the torque/current by varying the duty cycle, but you'll eventually fry either the motor or/and its driver.Use a servo motor plus a flexible "fingers": you'll control the angle the servo turns to and the "fingers" will transmit the pressure. A solenoid would be another solution.
void control(void) { int se0, set, er, PWMPct; PWMPct = 0; set = 50; se0 = a2dConvert8bit(0); //reads the 0th analog input, which is where my sensor is er = set - se0; //Initialize the PWM timer PWM_Init_timer2_H6(10); //Turn the PWM timer on PWM_timer2_On_H6(); //Set the direction port to +5V PORT_ON(PORTH,4); while(1) //Loop here instead of in main { PWMPct = PWMPct + er/10; if(PWMPct < 0) PWMPct = 0; if(PWMPct > 200) //bit of a safety factor... PWMPct = 200; PWM_timer2_Set_H6(PWMPct); delay_us(1000); //Necessary, or else the control law won't work (theoretically a smaller gain would fix this, but //Then I'd need better resolution timers se0 = a2dConvert8bit(0); er = set - se0; //Now we need to output to hyperterminal...but I'd rather not do it //every timestep :-( I guess I could just use timers and count, but it doesn't matter for now rprintf("Error: %d PWMPct %d ANALOG %d \n",er, PWMPct, se0);}[\code]