Added drive/stop
Embed:
(wiki syntax)
Show/hide line numbers
ICRS101.cpp
00001 #include "ICRS101.h" 00002 00003 PwmOut motor_left(MOTOR_LEFT_ENABLE); 00004 PwmOut motor_right(MOTOR_RIGHT_ENABLE); 00005 00006 DigitalOut motor_left_a(MOTOR_LEFT_A); 00007 DigitalOut motor_left_b(MOTOR_LEFT_B); 00008 DigitalOut motor_right_a(MOTOR_RIGHT_A); 00009 DigitalOut motor_right_b(MOTOR_RIGHT_B); 00010 00011 float global_speed = 0; 00012 00013 void run(float seconds); 00014 00015 void forward(float seconds) { 00016 00017 motor_left_a = 1; 00018 motor_left_b = 0; 00019 00020 motor_right_a = 1; 00021 motor_right_b = 0; 00022 00023 run(seconds); 00024 } 00025 00026 void backward(float seconds) { 00027 00028 motor_left_a = 0; 00029 motor_left_b = 1; 00030 00031 motor_right_a = 0; 00032 motor_right_b = 1; 00033 00034 run(seconds); 00035 } 00036 00037 void left(float seconds) { 00038 00039 motor_left_a = 1; 00040 motor_left_b = 0; 00041 00042 motor_right_a = 0; 00043 motor_right_b = 1; 00044 00045 run(seconds); 00046 } 00047 00048 void right(float seconds) { 00049 00050 motor_left_a = 0; 00051 motor_left_b = 1; 00052 00053 motor_right_a = 1; 00054 motor_right_b = 0; 00055 00056 run(seconds); 00057 } 00058 00059 void run(float seconds) 00060 { 00061 motor_left = global_speed; 00062 motor_right = global_speed; 00063 wait(seconds); 00064 motor_left = 0; 00065 motor_right = 0; 00066 } 00067 00068 void speed(float value) { 00069 global_speed = value; 00070 } 00071 00072 void drive(){ 00073 motor_left_a = 1; 00074 motor_left_b = 0; 00075 00076 motor_right_a = 1; 00077 motor_right_b = 0; 00078 00079 motor_left = global_speed; 00080 motor_right = global_speed; 00081 } 00082 00083 void stop(){ 00084 motor_left_a = 0; 00085 motor_left_b = 0; 00086 00087 motor_right_a = 0; 00088 motor_right_b = 0; 00089 00090 motor_left = 0; 00091 motor_right = 0; 00092 }
Generated on Thu Jul 14 2022 21:53:46 by
1.7.2