Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Brobot.cpp
00001 /* 00002 * BROBOT.cpp 00003 * 00004 */ 00005 00006 #include <cmath> 00007 #include "Brobot.h" 00008 00009 00010 Brobot::Brobot(PwmOut* left, PwmOut* right, int number) 00011 { 00012 pwmL = left; // set local references to objects 00013 pwmR = right; 00014 00015 this->number = number; 00016 } 00017 00018 // empty constructor 00019 Brobot::Brobot() 00020 {} 00021 00022 void Brobot::rotate( float phi) 00023 { 00024 if(phi>0.5f || phi<-0.5f) { 00025 phi=0; 00026 } 00027 00028 *pwmL = 0.5f + phi; 00029 *pwmR = 0.5f + phi; 00030 } 00031 00032 void Brobot::forward() 00033 { 00034 *pwmL=0.65f; // asterisk is dereferencing the pointer so 00035 *pwmR=0.36f; // you can access the variable at the pointers address 00036 // also another way to dereference the pointer is: pwmR->write(0.xx) 00037 } 00038 00039 void Brobot::slow(float scale) 00040 { 00041 if(scale>0.5f || scale<-0.5f) { 00042 scale=0; 00043 } 00044 00045 *pwmL = *pwmL - scale; 00046 *pwmR = *pwmR + scale; 00047 } 00048 00049 void Brobot::turnleft() 00050 { 00051 *pwmL=0.48f; 00052 *pwmR=0.31f; 00053 wait(0.1); 00054 } 00055 00056 void Brobot::turnright() 00057 { 00058 *pwmL=0.69f; 00059 *pwmR=0.52f; 00060 wait(0.1); 00061 } 00062 00063 void Brobot::back() 00064 { 00065 *pwmR=0.65f; 00066 *pwmL=0.35f; 00067 } 00068 00069 void Brobot::stop() 00070 { 00071 *pwmR=0.5f; 00072 *pwmL=0.5f; 00073 }
Generated on Wed Jul 13 2022 05:37:58 by
1.7.2