cout_put.cpp

  name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-5572165936844014&dt=1194442938015&lmt=1194190197&format=336x280_as&output=html&correlator=1194442937843&url=file%3A%2F%2F%2FC%3A%2FDocuments%2520and%2520Settings%2Flhh1%2F%E6%A1%8C%E9%9D%A2%2FCLanguage.htm&color_bg=FFFFFF&color_text=000000&color_link=000000&color_url=FFFFFF&color_border=FFFFFF&ad_type=text&ga_vid=583001034.1194442938&ga_sid=1194442938&ga_hid=1942779085&flash=9&u_h=768&u_w=1024&u_ah=740&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="336" scrolling="no" height="280" allowtransparency="allowtransparency"> #include <iostream.h>

void main(void)
 {
   char *title = "Jamsa's C/C++ Programmer's Bible";

   while (*title)
     cout.put(*title++);
 }

 

#include <array> #include <chrono> #include <iostream> #include <thread> #include <booster/idl/b1/LowCmd.h> #include <booster/idl/b1/MotorCmd.h> #include <booster/robot/b1/b1_api_const.hpp> #include <booster/robot/channel/channel_publisher.hpp> // Before you start to run this example, please make sure the robot is in "Prepare" mode. // Then start to run this example and press ENTER to start control. // In the same time, you should change the robot mode to "Custom" by api or controller. static const std::string kTopicLowSDK = booster::robot::b1::kTopicJointCtrl; using namespace booster::robot::b1; int main(int argc, char const *argv[]) { if (argc < 2) { std::cout << "Usage: " << argv[0] << " networkInterface" << std::endl; exit(-1); } booster::robot::ChannelFactory::Instance()->Init(0, argv[1]); booster::robot::ChannelPublisherPtr<booster_interface::msg::LowCmd> low_sdk_publisher; booster_interface::msg::LowCmd msg; low_sdk_publisher.reset( new booster::robot::ChannelPublisher<booster_interface::msg::LowCmd>( kTopicLowSDK)); low_sdk_publisher->InitChannel(); std::array<JointIndex, 23> low_joints = { JointIndex::kHeadYaw, JointIndex::kHeadPitch, JointIndex::kLeftShoulderPitch, JointIndex::kLeftShoulderRoll, JointIndex::kLeftElbowPitch, JointIndex::kLeftElbowYaw, JointIndex::kRightShoulderPitch, JointIndex::kRightShoulderRoll, JointIndex::kRightElbowPitch, JointIndex::kRightElbowYaw, JointIndex::kWaist, JointIndex::kLeftHipPitch, JointIndex::kLeftHipRoll, JointIndex::kLeftHipYaw, JointIndex::kLeftKneePitch, JointIndex::kCrankUpLeft, JointIndex::kCrankDownLeft, JointIndex::kRightHipPitch, JointIndex::kRightHipRoll, JointIndex::kRightHipYaw, JointIndex::kRightKneePitch, JointIndex::kCrankUpRight, JointIndex::kCrankDownRight }; float weight = 0.f; float weight_rate = 0.2f; float kp = 160.f; float kd = 5.5f; float dq = 0.f; float tau_ff = 0.f; float control_dt = 0.02f; float max_joint_velocity = 0.5f; float weight_margin = weight_rate * control_dt; float max_joint_delta = max_joint_velocity * control_dt; auto sleep_time = std::chrono::milliseconds(static_cast<int>(control_dt / 0.001f)); // msg.cmd_type(booster_interface::msg::CmdType::SERIAL); msg.cmd_type(booster_interface::msg::CmdType::PARALLEL); std::array<float, 23> init_pos{}; std::array<float, 23> target_pos = { 0.00, 0.00, 0.10, -1.50, 0.00, -0.20, 0.10, 1.50, 0.00, 0.20, 0.0, -0.2, 0., 0., 0.4, 0.2, 0.14, -0.2, 0., 0., 0.4, 0.2, 0.14,}; // std::array<float, 23> kps = {}; // std::array<float, 23> kds = {}; std::array<float, 23> kps = { 5., 5., 40., 50., 20., 10., 40., 50., 20., 10., 100., 350., 350., 180., 350., 550., 550., 350., 350., 180., 350., 550., 550., }; std::array<float, 23> kds = { .1, .1, .5, 1.5, .2, .2, .5, 1.5, .2, .2, 5.0, 7.5, 7.5, 3., 5.5, 1.5, 1.5, 7.5, 7.5, 3., 5.5, 1.5, 1.5, }; // std::array<float, 23> target_pos = { 0.00, 0.00, // 0.10, -1.50, 0.00, -0.20, // 0.10, 1.50, 0.00, 0.20, // 0.0, // -0.2, 0., 0., 0.4, -0.35, 0.03, // -0.2, 0., 0., 0.4, -0.35, -0.03,}; for (size_t i = 0; i < booster::robot::b1::kJointCnt; i++) { booster_interface::msg::MotorCmd motor_cmd; msg.motor_cmd().push_back(motor_cmd); } // wait for control std::cout << "Press ENTER to start ctrl ..." << std::endl; std::cin.get(); // start control std::cout << "Start low ctrl!" << std::endl; float period = 50000.f; int num_time_steps = static_cast<int>(period / control_dt); // std::array<float, 23> current_jpos_des{ // 0.00, 0.00, // 0.10, -1.50, 0.00, -0.20, // 0.10, 1.50, 0.00, 0.20, // 0.0, // -0.2, 0., 0., 0.4, 0.2, 0.14, // -0.2, 0., 0., 0.4, 0.2, 0.14, // }; std::array<float, 23> current_jpos_des = { 0.00, 0.00, 0.10, -1.50, 0.00, -0.20, 0.10, 1.50, 0.00, 0.20, 0.0, -0.2, 0., 0., 0.4, -0.35, 0.03, -0.2, 0., 0., 0.4, -0.35, -0.03,}; // lift lows up for (int i = 0; i < num_time_steps; ++i) { // update jpos des for (int j = 0; j < init_pos.size(); ++j) { current_jpos_des.at(j) += std::clamp(target_pos.at(j) - current_jpos_des.at(j), -max_joint_delta, max_joint_delta); } // set control joints for (int j = 0; j < init_pos.size(); ++j) { msg.motor_cmd().at(int(low_joints.at(j))).q(current_jpos_des.at(j)); msg.motor_cmd().at(int(low_joints.at(j))).dq(dq); msg.motor_cmd().at(int(low_joints.at(j))).kp(kps.at(j)); msg.motor_cmd().at(int(low_joints.at(j))).kd(kds.at(j)); msg.motor_cmd().at(int(low_joints.at(j))).tau(tau_ff); } // send dds msg low_sdk_publisher->Write(&msg); // sleep std::this_thread::sleep_for(sleep_time); } // put lows down // for (int i = 0; i < num_time_steps; ++i) { // // update jpos des // for (int j = 0; j < init_pos.size(); ++j) { // current_jpos_des.at(j) += // std::clamp(init_pos.at(j) - current_jpos_des.at(j), -max_joint_delta, // max_joint_delta); // } // // set control joints // for (int j = 0; j < init_pos.size(); ++j) { // msg.motor_cmd().at(int(low_joints.at(j))).q(current_jpos_des.at(j)); // msg.motor_cmd().at(int(low_joints.at(j))).dq(dq); // msg.motor_cmd().at(int(low_joints.at(j))).kp(kp); // msg.motor_cmd().at(int(low_joints.at(j))).kd(kd); // msg.motor_cmd().at(int(low_joints.at(j))).tau(tau_ff); // } // // send dds msg // low_sdk_publisher->Write(&msg); // // sleep // std::this_thread::sleep_for(sleep_time); // } // stop control std::cout << "Stoping low ctrl ..."; float stop_time = 2.0f; int stop_time_steps = static_cast<int>(stop_time / control_dt); for (int i = 0; i < stop_time_steps; ++i) { // increase weight weight -= weight_margin; weight = std::clamp(weight, 0.f, 1.f); // send dds msg low_sdk_publisher->Write(&msg); // sleep std::this_thread::sleep_for(sleep_time); } std::cout << "Done!" << std::endl; return 0; }
08-16
In file included from /workspace/x2/dfx/modules/hiviewx_watcher/component/log_watcher/main.cpp:6: /workspace/x2/dfx/modules/hiviewx_watcher/component/log_watcher/include/glog_sink.h: In member function ‘void CustomFileSink::ReopenLogFile()’: /workspace/x2/dfx/modules/hiviewx_watcher/component/log_watcher/include/glog_sink.h:250:43: error: cannot convert ‘std::basic_ofstream<char>::__filebuf_type*’ {aka ‘std::basic_filebuf<char>*’} to ‘FILE*’ 250 | int fd = fileno(outfile_.rdbuf()); | ~~~~~~~~~~~~~~^~ | | | std::basic_ofstream<char>::__filebuf_type* {aka std::basic_filebuf<char>*} In file included from /usr/include/c++/11/cstdio:42, from /usr/include/c++/11/ext/string_conversions.h:43, from /usr/include/c++/11/bits/basic_string.h:6608, from /usr/include/c++/11/string:55, from /usr/include/c++/11/stdexcept:39, from /usr/include/boost/asio/execution/receiver_invocation_error.hpp:19, from /usr/include/boost/asio/execution/detail/as_invocable.hpp:22, from /usr/include/boost/asio/execution/execute.hpp:20, from /usr/include/boost/asio/execution/executor.hpp:20, from /usr/include/boost/asio/associated_executor.hpp:20, from /usr/include/boost/asio.hpp:21, from /workspace/x2/dfx/modules/hiviewx_watcher/component/log_watcher/main.cpp:2: /usr/include/stdio.h:809:26: note: initializing argument 1 of ‘int fileno(FILE*)’ 809 | extern int fileno (FILE *__stream) __THROW __wur; | ~~~~~~^~~~~~~~ make[2]: *** [modules/hiviewx_watcher/component/log_watcher/CMakeFiles/log_watcher.dir/build.make:76: modules/hiviewx_watcher/component/log_watcher/CMakeFiles/log_watcher.dir/main.cpp.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:585: modules/hiviewx_watcher/component/log_watcher/CMakeFiles/log_watcher.dir/all] Error 2 make: *** [Makefile:136: all] Error 2 ================================================== 这是我的报错信息. void ReopenLogFile() { std::lock_guard<std::mutex> lock(file_mutex_); // 先关闭现有文件 if (outfile_.is_open()) { outfile_.flush(); outfile_.close(); } // 确保目录存在 auto dir_path = std::filesystem::path(log_file_path_).parent_path(); if (!dir_path.empty()) { std::filesystem::create_directories(dir_path); } // 重新打开文件 outfile_.open(log_file_path_, std::ios::out | std::ios::app); if (!outfile_.is_open()) { std::cerr << "[ERROR] Failed to open log file: " << log_file_path_ << " - " << strerror(errno) << std::endl; } else { std::cout << "[DEBUG] Successfully reopened log file: " << log_file_path_ << std::endl; // 获取底层文件描述符 (仅用于调试) int fd = fileno(outfile_.rdbuf()); std::cout << "[DEBUG] New file descriptor: " << fd << std::endl; // 强制立即写入到磁盘 fsync(fd); } }这是我的代码.错误如何修改呢
07-30
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值