<commit_before>/*
 * pole.cpp
 *
 *  Created on: Sep 15, 2010
 *      Author: baj
 */

#include "pole.h"
#include "logger.h"

void Pole::step(int action)
{
	/*** Parameters for simulation ***/
	static const double GRAVITY = 9.8;
	static const double MASSCART = 1.0;
	static const double MASSPOLE = 0.1;
	static const double TOTAL_MASS = MASSPOLE + MASSCART;
	static const double LENGTH = 0.5;        /* actually half the pole's length */
	static const double POLEMASS_LENGTH = (MASSPOLE * LENGTH);
	static const double FORCE_MAG = 10.0;
	static const double TAU = 0.02;          /* seconds between state updates */
	static const double FOURTHIRDS = 1.3333333333333;

	double force = (!action)? 0: ((action > 0)? FORCE_MAG : -FORCE_MAG);

	force += irand(-FORCE_MAG, FORCE_MAG) * 0.1; //

	double costheta = cos(theta_);
	double sintheta = sin(theta_);

	double temp = (force + POLEMASS_LENGTH * dtheta_ * dtheta_ * sintheta) / TOTAL_MASS;
	double thetaacc = (GRAVITY * sintheta - costheta * temp) / (LENGTH * (FOURTHIRDS - MASSPOLE * costheta * costheta / TOTAL_MASS));
	double xacc  = temp - POLEMASS_LENGTH * thetaacc * costheta / TOTAL_MASS;

	/*** Update the four state variables, using Euler's method. ***/
	x_  += TAU * dx_;
	dx_ += TAU * xacc;

	theta_ += TAU * dtheta_;
	dtheta_ += TAU * thetaacc;

	theta_ = normalize_angle(theta_);
	dtheta_ = normalize_angle(dtheta_);

}

void Pole::log(Logger *logger, int action)
{
	static const double cart_width = 0.2;
	static const double cart_height = 0.075;
	static const double pole_len = 0.5;

	//cart-poleϵ
	Logger::Rectangular cart(x_ - cart_width * 0.5, x_ + cart_width * 0.5, cart_height,	0.0);
	Logger::Vector pole_top = Logger::Vector(x_ + pole_len * sin(theta_), cart_height + pole_len * cos(theta_));
	Logger::Vector pole_bottom = Logger::Vector(x_ , cart_height);

	static const double x_scale = 250.0;<commit_msg>fix bug of dtheta_ normalization<commit_after>/*
 * pole.cpp
 *
 *  Created on: Sep 15, 2010
 *      Author: baj
 */

#include "pole.h"
#include "logger.h"

void Pole::step(int action)
{
	/*** Parameters for simulation ***/
	static const double GRAVITY = 9.8;
	static const double MASSCART = 1.0;
	static const double MASSPOLE = 0.1;
	static const double TOTAL_MASS = MASSPOLE + MASSCART;
	static const double LENGTH = 0.5;        /* actually half the pole's length */
	static const double POLEMASS_LENGTH = (MASSPOLE * LENGTH);
	static const double FORCE_MAG = 10.0;
	static const double TAU = 0.02;          /* seconds between state updates */
	static const double FOURTHIRDS = 1.3333333333333;

	double force = (!action)? 0: ((action > 0)? FORCE_MAG : -FORCE_MAG);

	force += irand(-FORCE_MAG, FORCE_MAG) * 0.1; //

	double costheta = cos(theta_);
	double sintheta = sin(theta_);

	double temp = (force + POLEMASS_LENGTH * dtheta_ * dtheta_ * sintheta) / TOTAL_MASS;
	double thetaacc = (GRAVITY * sintheta - costheta * temp) / (LENGTH * (FOURTHIRDS - MASSPOLE * costheta * costheta / TOTAL_MASS));
	double xacc  = temp - POLEMASS_LENGTH * thetaacc * costheta / TOTAL_MASS;

	/*** Update the four state variables, using Euler's method. ***/
	x_  += TAU * dx_;
	dx_ += TAU * xacc;

	theta_ += TAU * dtheta_;
	dtheta_ += TAU * thetaacc;

	theta_ = normalize_angle(theta_);
}

void Pole::log(Logger *logger, int action)
{
	static const double cart_width = 0.2;
	static const double cart_height = 0.075;
	static const double pole_len = 0.5;

	//cart-poleϵ
	Logger::Rectangular cart(x_ - cart_width * 0.5, x_ + cart_width * 0.5, cart_height,	0.0);
	Logger::Vector pole_top = Logger::Vector(x_ + pole_len * sin(theta_), cart_height + pole_len * cos(theta_));
	Logger::Vector pole_bottom = Logger::Vector(x_ , cart_height);

	static const double x_scale = 250.0;
{'fraction_non_alphanumeric': 0.1269756228234664, 'fraction_numerical': 0.03000267881060809, 'mean_word_length': 3.7994858611825193, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6665346', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1335, 'n_words': 383}