Firmware for Arduino | PLEN Project Company Inc.
PLEN2::JointController Class Reference

Management class of joints. More...

#include <JointController.h>

Classes

class  Multiplexer
 Management class (as namespace) of multiplexer. More...
 

Public Types

enum  JOINT_INDEX {
  LEFT_SHOULDER_PITCH = 0, LEFT_THIGH_YAW = 1, LEFT_SHOULDER_ROLL = 2, LEFT_ELBOW_ROLL = 3,
  LEFT_THIGH_ROLL = 4, LEFT_THIGH_PITCH = 5, LEFT_KNEE_PITCH = 6, LEFT_FOOT_PITCH = 7,
  LEFT_FOOT_ROLL = 8, RIGHT_SHOULDER_PITCH = 12, RIGHT_THIGH_YAW = 13, RIGHT_SHOULDER_ROLL = 14,
  RIGHT_ELBOW_ROLL = 15, RIGHT_THIGH_ROLL = 16, RIGHT_THIGH_PITCH = 17, RIGHT_KNEE_PITCH = 18,
  RIGHT_FOOT_PITCH = 19, RIGHT_FOOT_ROLL = 20
}
 
enum  BASIC_JOINT_SETTINGS { JOINTS_SUM = 24 }
 

Public Member Functions

 JointController ()
 Constructor. More...
 
void loadSettings ()
 Load the joint settings. More...
 
void resetSettings ()
 Reset the joint settings. More...
 
const int16_t & getMinAngle (uint8_t joint_id)
 Get min angle of the joint given. More...
 
const int16_t & getMaxAngle (uint8_t joint_id)
 Get max angle of the joint given. More...
 
const int16_t & getHomeAngle (uint8_t joint_id)
 Get home angle of the joint given. More...
 
bool setMinAngle (uint8_t joint_id, int16_t angle)
 Set min angle of the joint given. More...
 
bool setMaxAngle (uint8_t joint_id, int16_t angle)
 Set max angle of the joint given. More...
 
bool setHomeAngle (uint8_t joint_id, int16_t angle)
 Set home angle of the joint given. More...
 
bool setAngle (uint8_t joint_id, int16_t angle)
 Set angle of the joint given. More...
 
bool setAngleDiff (uint8_t joint_id, int16_t angle_diff)
 Set angle to "angle-diff + home-angle" of the joint given. More...
 
void dump ()
 Dump the joint settings. More...
 

Static Public Attributes

static volatile bool m_1cycle_finished
 Finished flag of PWM output procedure 1 cycle. More...
 
static uint16_t m_pwms [JOINTS_SUM]
 PWM buffer. More...
 

Detailed Description

Management class of joints.

In Atmega32u4, one timer can output 3 PWM signals at a time. The MCU can control 24 servos by connecting 3bit multiplexer in each signal output lines.

Member Enumeration Documentation

Enumerator
JOINTS_SUM 

Summation of the servos controllable.

Enumerator
LEFT_SHOULDER_PITCH 
LEFT_THIGH_YAW 
LEFT_SHOULDER_ROLL 
LEFT_ELBOW_ROLL 
LEFT_THIGH_ROLL 
LEFT_THIGH_PITCH 
LEFT_KNEE_PITCH 
LEFT_FOOT_PITCH 
LEFT_FOOT_ROLL 
RIGHT_SHOULDER_PITCH 
RIGHT_THIGH_YAW 
RIGHT_SHOULDER_ROLL 
RIGHT_ELBOW_ROLL 
RIGHT_THIGH_ROLL 
RIGHT_THIGH_PITCH 
RIGHT_KNEE_PITCH 
RIGHT_FOOT_PITCH 
RIGHT_FOOT_ROLL 

Constructor & Destructor Documentation

PLEN2::JointController::JointController ( )

Constructor.

Member Function Documentation

void PLEN2::JointController::dump ( )

Dump the joint settings.

Output result in JSON format as below.

[
{
"@device": <integer>,
"max": <integer>,
"min": <integer>,
"home": <integer>
},
...
]
const int16_t& PLEN2::JointController::getHomeAngle ( uint8_t  joint_id)

Get home angle of the joint given.

Parameters
[in]joint_idPlease set the joint id from which you want to get home angle.
Returns
Reference of home angle a joint expressed by joint_id has.
Return values
-32768Argument error. (joint_id is invalid.)
const int16_t& PLEN2::JointController::getMaxAngle ( uint8_t  joint_id)

Get max angle of the joint given.

Parameters
[in]joint_idPlease set the joint id from which you want to get max angle.
Returns
Reference of max angle of a joint described by joint_id.
Return values
-32768Argument error. (joint_id is invalid.)
const int16_t& PLEN2::JointController::getMinAngle ( uint8_t  joint_id)

Get min angle of the joint given.

Parameters
[in]joint_idPlease set the joint id from which you want to get min angle.
Returns
Reference of min angle of a joint described by joint_id.
Return values
-32768Argument error. (joint_id is invalid.)
void PLEN2::JointController::loadSettings ( )

Load the joint settings.

The method reads joint settings from internal EEPROM. If the EEPROM has no settings, the method also writes the default values.

See also
JointController.cpp::Shared::m_SETTINGS_INITIAL
Attention
The method should be called in constructor normally, but initialized timing of any interruption is indefinite, so it might get deadlocked. (The method uses serial communication and internal EEPROM access, so interruption happens.)
void PLEN2::JointController::resetSettings ( )

Reset the joint settings.

Write default settings to internal EEPROM.

bool PLEN2::JointController::setAngle ( uint8_t  joint_id,
int16_t  angle 
)

Set angle of the joint given.

Parameters
[in]joint_idPlease set the joint id from which you want to set the angle.
[in]anglePlease set angle that has steps of degree 1/10.
Returns
Result
Attention
angle might not be set actually. It is set after trimming by user defined min-max value or servo's range, so please consider it when writing a unit test.
bool PLEN2::JointController::setAngleDiff ( uint8_t  joint_id,
int16_t  angle_diff 
)

Set angle to "angle-diff + home-angle" of the joint given.

Parameters
[in]joint_idPlease set the joint id from which you want to set the angle-diff.
[in]angle_diffPlease set angle-diff that has steps of degree 1/10.
Returns
Result
Attention
angle_diff might not be set actually. It is set after trimming by user defined min-max value or servo's range, so please consider it when writing a unit test.
bool PLEN2::JointController::setHomeAngle ( uint8_t  joint_id,
int16_t  angle 
)

Set home angle of the joint given.

Parameters
[in]joint_idPlease set the joint id from which you want to define the home angle.
[in]anglePlease set angle that has steps of degree 1/10.
Returns
Result
bool PLEN2::JointController::setMaxAngle ( uint8_t  joint_id,
int16_t  angle 
)

Set max angle of the joint given.

Parameters
[in]joint_idPlease set the joint id from which you want to define the max angle.
[in]anglePlease set angle that has steps of degree 1/10.
Returns
Result
bool PLEN2::JointController::setMinAngle ( uint8_t  joint_id,
int16_t  angle 
)

Set min angle of the joint given.

Parameters
[in]joint_idPlease set the joint id from which you want to define the min angle.
[in]anglePlease set angle that has steps of degree 1/10.
Returns
Result

Member Data Documentation

volatile bool PLEN2::JointController::m_1cycle_finished
static

Finished flag of PWM output procedure 1 cycle.

Attention
The instance should be a private member normally. It is a public member because it is the only way to access it from Timer 1 overflow interruption vector, so you must not access it from other functions basically.
uint16_t PLEN2::JointController::m_pwms[JOINTS_SUM]
static

PWM buffer.

Attention
The instance should be a private member normally. It is a public member because it is the only way to access it from Timer 1 overflow interruption vector, so you must not access it from other functions basically.

The documentation for this class was generated from the following file: