Team repo
Embed:
(wiki syntax)
Show/hide line numbers
pot.cpp
00001 #include "mbed.h" 00002 #include "pot.h" 00003 00004 00005 Pot::Pot(PinName _pin, QEI* motor_encoder, float offset) : pend_angle(_pin),encoder() { 00006 encoder=motor_encoder; 00007 offset=offset; 00008 00009 } 00010 00011 void Pot::update(){ 00012 //angular_velocity = (get_angle() - angle)/ UPDATE_TIME; 00013 angle=get_angle_pulse(); 00014 //velocity = (get_position() - position) / UPDATE_TIME; 00015 //position=get_position(); 00016 } 00017 00018 void Pot::set_zeros(){ 00019 this->offset = (-1)*this->get_angle(); 00020 this->encoder->reset(); 00021 wait(2); 00022 } 00023 00024 float Pot::get_angle(){ 00025 float a = pend_angle.read() * VOLTAGE_ANGLE_RATIO + offset; 00026 return a; 00027 } 00028 00029 float Pot::get_angle_pulse(){ 00030 float b = (float) 360/ (float)1024; 00031 float a = ((float)encoder->getPulses()*b); 00032 return a; 00033 } 00034 00035 float Pot::get_position(){ 00036 float a = (-1)*encoder->getPulses()*CM_PER_PULSE; 00037 return a; 00038 } 00039 00040 float Pot::angle_as_voltage(){ 00041 float a = pend_angle.read(); 00042 return a; 00043 } 00044 00045 int Pot::position_as_pulse(){ 00046 return this->encoder->getPulses(); 00047 } 00048 00049 void Pot::print_test(){ 00050 printf("Position: %f \tVelocity: %f \tAngle: %f \tAngular Velocity: %f \r\n", position, velocity, angle, angular_velocity); 00051 } 00052 00053 00054 00055 00056
Generated on Sat Jul 16 2022 15:10:49 by
1.7.2