Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
#include "hardware.h" //iopin ,actuators , axon... are included here// and 2 motors (right and left) are initilized here too.#include "movements.h" #include "controlManual.h"#include "l298.h" // //define the type of control#define manualvoid appInitHardware(void){pin_make_output( E2, false );pin_make_output( A4, false );pin_make_output( H2, false );pin_make_output( A5, false );uartInit(UART1, 115200);solarL298Init(&bank1);rprintfInit(&uart1SendByte);rprintfProgStrM("System Warmed UP. .Initialization Complete\n");}TICK_COUNT appInitSoftware(TICK_COUNT loopStart){ turnOnL298(); // this method turn on the pins of L298 act_setSpeed(&left,DRIVE_SPEED_MAX*0.5); act_setSpeed(&right,DRIVE_SPEED_MAX*0.5);return 0;}TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){ act_setSpeed(&left,DRIVE_SPEED_MAX * n); act_setSpeed(&right,DRIVE_SPEED_MAX * n); // this "n" is like a control of the speed , i want control the speed of //each motor. and HERE IS THE PROBLEM (i think)! //*0<=n<=1 #ifdef manual controlManual(); #endif return 1000000; }
void controlManual(){ // Get an key from keyboard.then the methods move , back , turn left ,turn//right ,top , set the PINs true or false, to make the motor spin the way i want.// Like if i press w, he will move forward then, i set values to my pin char cByte = GET_DATA_USB; switch ( cByte ){ case 'w': move(); front(); break; case 's': move(); back(); break; case 'd': move(); turnRight(); break; case 'a': move(); turnLeft(); break; default: stop(); } }
void front(){ pin_set( E2, false ); pin_set( H2, true );}void back(){ pin_set( E2, true ); pin_set( H2, false );}void turnRight(){ pin_set( E2, false); pin_set( H2, false );}void turnLeft(){ pin_set( E2, true ); pin_set( H2, true );}void stop(){ pin_low( A4 ); pin_low( A5 );}void move(){ pin_high( A4 ); pin_high( A5 );}