note_cpp: time start - stop

本文介绍了一种使用C++标准库中的time和unistd.h库来测量时间差的方法。通过记录开始和结束的时间戳,并利用time(NULL)获取当前时间,再通过sleep函数暂停一段时间,最后计算并输出这段时间差。
#include <iostream>
#include <unistd.h> 
#include <ctime>

using namespace std;
int main()
{
	time_t start_door;
	time_t stop_door;
	start_door= time(NULL);
	sleep(3);
	stop_door= time(NULL);
	cout << stop_door - start_door<< " seconds has passed";
	return 0;
}

 

我的错误类型是生成开始于 10:13... 1>------ 已启动生成: 项目: ConsoleApplication1, 配置: Debug x64 ------ 1> ConsoleApplication1.cpp 1> Unknown compiler version - please run the configure tests and report the results 1>Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\kernel\sc_attribute.h(110,29): warning C4267: “return”: 从“size_t”转换到“int”,可能丢失数据 1> (compiling source file 'ConsoleApplication1.cpp') 1>Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\communication\sc_export.h(225,35): warning C4267: “return”: 从“size_t”转换到“int”,可能丢失数据 1> (compiling source file 'ConsoleApplication1.cpp') 1>Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\kernel\sc_simcontext.h(556,36): warning C4267: “return”: 从“size_t”转换到“int”,可能丢失数据 1> (compiling source file 'ConsoleApplication1.cpp') 1>Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\kernel\sc_event.h(548,25): warning C4267: “return”: 从“size_t”转换到“int”,可能丢失数据 1> (compiling source file 'ConsoleApplication1.cpp') 1>Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\communication\sc_port.h(199,33): warning C4267: “return”: 从“size_t”转换到“int”,可能丢失数据 1> (compiling source file 'ConsoleApplication1.cpp') 1>Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\communication\sc_prim_channel.h(239,41): warning C4267: “return”: 从“size_t”转换到“int”,可能丢失数据 1> (compiling source file 'ConsoleApplication1.cpp') 1>Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\packages\boost\utility\enable_if.hpp(1,1): warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失 1> (compiling source file 'ConsoleApplication1.cpp') 1>Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\utils\sc_vector.h(271,3): error C4996: 'std::iterator<std::random_access_iterator_tag,sc_vector_iter<ElementType,AccessPolicy>::access_policy::type,ptrdiff_t,sc_vector_iter<ElementType,AccessPolicy>::access_policy::type*,sc_vector_iter<ElementType,AccessPolicy>::access_policy::type&>': warning STL4015: The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17. (The <iterator> header is NOT deprecated.) The C++ Standard has never required user-defined iterators to derive from std::iterator. To fix this warning, stop deriving from std::iterator and start providing publicly accessible typedefs named iterator_category, value_type, difference_type, pointer, and reference. Note that value_type is required to be non-const, even for constant iterators. You can define _SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to suppress this warning. 1> (compiling source file 'ConsoleApplication1.cpp') 1> Z:\VisualStudio\VC\Tools\MSVC\14.50.35717\include\xutility(7698,45): 1> 参见“std::iterator”的声明 1> Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\utils\sc_vector.h(271,3): 1> 模板实例化上下文(最早的实例化上下文)为 1> Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\utils\sc_vector.h(253,7): 1> 在编译类模板“sc_core::sc_vector_iter”时 1>Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\communication\sc_port.h(605,18): warning C4267: “初始化”: 从“size_t”转换到“int”,可能丢失数据 1> (compiling source file 'ConsoleApplication1.cpp') 1> Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\communication\sc_port.h(605,18): 1> 模板实例化上下文(最早的实例化上下文)为 1> Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\communication\sc_signal_ports.h(390,12): 1> 查看对正在编译的 类 模板 实例化“sc_core::sc_port<sc_core::sc_signal_in_if<bool>,1,sc_core::SC_ONE_OR_MORE_BOUND>”的引用 1> Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\communication\sc_port.h(374,10): 1> 查看对正在编译的 类 模板 实例化“sc_core::sc_port_b<IF>”的引用 1> with 1> [ 1> IF=sc_core::sc_signal_in_if<bool> 1> ] 1> Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\communication\sc_port.h(602,1): 1> 在编译 类 模板 成员函数“void sc_core::sc_port_b<IF>::make_sensitive(sc_core::sc_method_handle,sc_core::sc_event_finder *) const”时 1> with 1> [ 1> IF=sc_core::sc_signal_in_if<bool> 1> ] 1>Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\communication\sc_port.h(584,18): warning C4267: “初始化”: 从“size_t”转换到“int”,可能丢失数据 1> (compiling source file 'ConsoleApplication1.cpp') 1> Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\communication\sc_port.h(584,18): 1> 模板实例化上下文(最早的实例化上下文)为 1> Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\communication\sc_port.h(581,1): 1> 在编译 类 模板 成员函数“void sc_core::sc_port_b<IF>::make_sensitive(sc_core::sc_thread_handle,sc_core::sc_event_finder *) const”时 1> with 1> [ 1> IF=sc_core::sc_signal_in_if<bool> 1> ] 1>Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\communication\sc_port.h(545,14): warning C4267: “初始化”: 从“size_t”转换到“int”,可能丢失数据 1> (compiling source file 'ConsoleApplication1.cpp') 1> Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\communication\sc_port.h(545,14): 1> 模板实例化上下文(最早的实例化上下文)为 1> Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\communication\sc_port.h(539,1): 1> 在编译 类 模板 成员函数“void sc_core::sc_port_b<IF>::add_interface(sc_core::sc_interface *)”时 1> with 1> [ 1> IF=sc_core::sc_signal_in_if<bool> 1> ] 1>Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\communication\sc_port.h(574,29): warning C4267: “return”: 从“size_t”转换到“int”,可能丢失数据 1> (compiling source file 'ConsoleApplication1.cpp') 1> Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\communication\sc_port.h(574,29): 1> 模板实例化上下文(最早的实例化上下文)为 1> Z:\systemc-2.3.1\systemc-2.3.1\src\sysc\communication\sc_port.h(573,1): 1> 在编译 类 模板 成员函数“int sc_core::sc_port_b<IF>::interface_count(void)”时 1> with 1> [ 1> IF=sc_core::sc_signal_in_if<bool> 1> ] ========== 生成: 0 成功,1 失败,0 最新,0 已跳过 ========== ========== 生成 于 10:13 完成,耗时 22.528 秒 ==========
12-19
#ifndef CTRL_FSM_WAYPOINTS_H #define CTRL_FSM_WAYPOINTS_H #include <cmath> #include <string> #include <ros/ros.h> #include <ros/callback_queue.h> #include <std_msgs/Bool.h> #include <std_msgs/Int32.h> #include <sensor_msgs/Imu.h> #include <nav_msgs/Odometry.h> #include <geometry_msgs/PoseArray.h> #include <geometry_msgs/PoseStamped.h> #include <mavros_msgs/State.h> #include <common/visual.hpp> #include <common/trajectory.hpp> #include <common/quat_euler_convert.hpp> #include <ctrl/motion_controller_separate.h> class CtrlFSMWaypoints { public: // Constructor CtrlFSMWaypoints() = delete; CtrlFSMWaypoints(const ros::NodeHandle &nh, const ros::NodeHandle &pnh); CtrlFSMWaypoints(const CtrlFSMWaypoints &rhs) = delete; CtrlFSMWaypoints &operator=(const CtrlFSMWaypoints &rhs) = delete; CtrlFSMWaypoints(CtrlFSMWaypoints &&rhs) = delete; CtrlFSMWaypoints &operator=(CtrlFSMWaypoints &&rhs) = delete; virtual ~CtrlFSMWaypoints() {} private: // State Machine enum FSM_EXEC_STATE { INIT, HOVER, CMD_CTRL, WAIT }; FSM_EXEC_STATE exec_state_; std_msgs::Int32 exec_state_int_; float hover_yaw_; Eigen::Vector2f hover_pos_; bool have_odom_; bool have_traj_; bool new_hover_flag_; bool is_ground_; bool follow_traj_finished_; bool is_armed_; bool emergency_stop_flag_; // ROS NodeHandle ros::NodeHandle nh_; ros::NodeHandle pnh_; // ROS Subscribers ros::Subscriber odom_sub_; ros::Subscriber run_trigger_sub_; ros::Subscriber flight_status_sub_; ros::Subscriber mavros_state_sub_; ros::Subscriber waypoints_list_sub_; ros::Subscriber goal_sub_; ros::Subscriber emergency_stop_sub_; // ROS Publishers ros::Publisher attitude_target_pub_; ros::Publisher follow_traj_finished_pub_; ros::Publisher ground_ctrl_fsm_pub_; // ROS Timers ros::Timer run_timer_; // ROS Topics std::string odometry_topic_; std::string run_trigger_topic_; std::string attitude_target_topic_; std::string flight_status_topic_; std::string follow_traj_finished_topic_; std::string waypoints_list_topic_; std::string ground_ctrl_fsm_topic_; std::string goal_topic_; std::string emergency_stop_topic_; // Variables common::trajectory::CurEstimate<float> cur_estimate_; double traj_duration_; ros::Time start_time_; minco_utils::Trajectory follow_traj_; geometry_msgs::PoseStamped run_trigger_msg_; bool loop_tracking_flag_; int eight_count_; // Only used in subscribe waypoints_list_callback int eight_count_expected_; double eight_length_; double eight_width_; bool adding_eight_traj_; // PID Controller Parameters PIDParams position_pid_params_; PIDParams velocity_pid_params_; PIDParams pitch_pid_params_; PIDParams yaw_pid_params_; // Common Parameters CommonParams common_params_; // Thrust Parameters float thrust_return_; bool use_thrust_change_; // Waypoints Parameters int waypoint_num_; double interpolation_dis_; bool using_waypoints_params_; Eigen::MatrixXd final_state_; std::vector<Eigen::Vector3d> Q_; std::vector<Eigen::Vector3d> waypoints_; // Minco Trajectory Parameters minco_utils::MincoTrajParams traj_params_; // Visualizer the trajectory common::visual::TrajectoryVisualizer::Ptr traj_visualizer_; // Motion Controller MotionControllerSeparate::Ptr motion_controller_; // Functions void changeFSMExecState(FSM_EXEC_STATE new_state, string pos_call); void printFSMExecState(); // Callback functions void odomCallback(const nav_msgs::Odometry::ConstPtr &msg_ptr); void runTriggerCallback(const geometry_msgs::PoseStamped::ConstPtr &msg_ptr); void flightStatusCallback(const std_msgs::Bool::ConstPtr &msg_ptr); void mavrosStateCallback(const mavros_msgs::State::ConstPtr &msg_ptr); void waypointsListCallback(const geometry_msgs::PoseArray::ConstPtr &msg_ptr); void goalCallback(const geometry_msgs::PoseStamped::ConstPtr &msg_ptr); void emergencyStopCallback(const std_msgs::Bool::ConstPtr &msg_ptr); void runTimerCallback(const ros::TimerEvent &event); void publishAttitudeTarget(const std::pair<float, float> &desired_attitude, const float &feedforward_pitch_rate, const float &feedforward_yaw_rate); }; #endif // CTRL_FSM_WAYPOINTS_H 注释上述代码
09-20
..\..\MainWindow.cpp(28): error C2665: “op::PoseExtractorCaffe::PoseExtractorCaffe”: 没有重载函数可以转换所有参数类型 C:\openpose-prosperity\include\openpose/pose/poseExtractorCaffe.hpp(19): note: 可能是“op::PoseExtractorCaffe::PoseExtractorCaffe(const op::PoseModel,const std::string &,const int,const std::vector<op::HeatMapType,std::allocator<op::HeatMapType>> &,const op::ScaleMode,const bool,const bool,const std::string &,const std::string &,const float,const bool,const bool)” ..\..\MainWindow.cpp(28): note: “op::PoseExtractorCaffe::PoseExtractorCaffe(const op::PoseModel,const std::string &,const int,const std::vector<op::HeatMapType,std::allocator<op::HeatMapType>> &,const op::ScaleMode,const bool,const bool,const std::string &,const std::string &,const float,const bool,const bool)”: 无法将参数 7 从“op::Point<int>”转换为“const bool” ..\..\MainWindow.cpp(35): note: 没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符 ..\..\MainWindow.cpp(28): note: 尝试匹配参数列表“(op::PoseModel, const char [30], int, std::vector<op::HeatMapType,std::allocator<op::HeatMapType>>, op::ScaleMode, bool, op::Point<int>)”时 ..\..\MainWindow.cpp(116): error C2440: “<function-style-cast>”: 无法从“initializer list”转换为“op::Matrix” ..\..\MainWindow.cpp(116): note: “op::Matrix::Matrix”: 没有重载函数可以转换所有参数类型 C:\openpose-prosperity\include\openpose/core/matrix.hpp(118): note: 可能是“op::Matrix::Matrix(const int,const int,const int)” ..\..\MainWindow.cpp(116): note: “op::Matrix::Matrix(const int,const int,const int)”: 无法将参数 3 从“uchar *”转换为“const int” ..\..\MainWindow.cpp(116): note: 没有使该转换得以执行的上下文 ..\..\MainWindow.cpp(116): note: 尝试匹配参数列表“(int, int, uchar *)”时 ..\..\MainWindow.cpp(117): error C2039: "copyFrom": 不是 "op::Array<float>" 的成员 C:\openpose-prosperity\include\openpose/core/array.hpp(21): note: 参见“op::Array<float>”的声明 ..\..\MainWindow.cpp(120): error C2039: "forward": 不是 "op::PoseExtractorCaffe" 的成员 C:\openpose-prosperity\include\openpose/pose/poseExtractorCaffe.hpp(16): note: 参见“op::PoseExtractorCaffe”的声明 cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -permissive- -Zc:__cplusplus -Zc:externConstexpr -O2 -MD -std:c++17 -utf-8 -W3 -w34100 -w34189 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DOPENPOSE_MODEL_PATH="\"C:/openpose-prosperity/models\"" -DNDEBUG -DQT_QML_DEBUG -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_MULTIMEDIA_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I..\..\..\untitled1 -I. -IC:\openpose-prosperity\include -IC:\opencv\build\include -I"C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.44.35207\include" -IC:\Qt\6.10.0\msvc2022_64\include -IC:\Qt\6.10.0\msvc2022_64\include\QtWidgets -IC:\Qt\6.10.0\msvc2022_64\include\QtMultimedia -IC:\Qt\6.10.0\msvc2022_64\include\QtGui -IC:\Qt\6.10.0\msvc2022_64\include\QtNetwork -IC:\Qt\6.10.0\msvc2022_64\include\QtCore -Irelease -I. -I/include -IC:\Qt\6.10.0\msvc2022_64\mkspecs\win32-msvc -Forelease\ @C:\Users\admin\AppData\Local\Temp\moc_MainWindow.obj.5052.1171.jom moc_MainWindow.cpp jom: C:\Users\admin\Desktop\QT\untitled1\build\Desktop_Qt_6_10_0_MSVC2022_64bit-Debug\Makefile.Release [release\MainWindow.obj] Error 2 jom: C:\Users\admin\Desktop\QT\untitled1\build\Desktop_Qt_6_10_0_MSVC2022_64bit-Debug\Makefile [release] Error 2 00:17:11: The command "C:\Qt\Tools\QtCreator\bin\jom\jom.exe" terminated with exit code 2. 00:17:11: Error while building/deploying project untitled1 (kit: Desktop Qt 6.10.0 MSVC2022 64bit) 00:17:11: The kit Desktop Qt 6.10.0 MSVC2022 64bit has configuration issues which might be the root cause for this problem. 00:17:11: When executing step "Make" 00:17:11: Elapsed time: 00:08.
11-22
#ifndef CTRL_FSM_PLANNING_H #define CTRL_FSM_PLANNING_H #include <cmath> #include <string> #include <ros/ros.h> #include <ros/callback_queue.h> #include <std_msgs/Bool.h> #include <std_msgs/Int32.h> #include <sensor_msgs/Imu.h> #include <nav_msgs/Odometry.h> #include <geometry_msgs/PoseArray.h> #include <geometry_msgs/PoseStamped.h> #include <mavros_msgs/State.h> #include <common/visual.hpp> #include <common/trajectory.hpp> #include <common/quat_euler_convert.hpp> #include <ctrl/motion_controller_separate.h> #include <common/traj_anal.hpp> #include <carstatemsgs/Polynome.h> class CtrlFSMPlanningDDR { public: // Constructor CtrlFSMPlanningDDR() = delete; CtrlFSMPlanningDDR(const ros::NodeHandle &nh, const ros::NodeHandle &pnh); CtrlFSMPlanningDDR(const CtrlFSMPlanningDDR &rhs) = delete; CtrlFSMPlanningDDR &operator=(const CtrlFSMPlanningDDR &rhs) = delete; CtrlFSMPlanningDDR(CtrlFSMPlanningDDR &&rhs) = delete; CtrlFSMPlanningDDR &operator=(CtrlFSMPlanningDDR &&rhs) = delete; virtual ~CtrlFSMPlanningDDR() {} private: // State Machine enum FSM_EXEC_STATE { INIT, HOVER, CMD_CTRL, WAIT }; FSM_EXEC_STATE exec_state_; std_msgs::Int32 exec_state_int_; float hover_yaw_; Eigen::Vector2f hover_pos_; bool have_odom_; bool have_traj_; bool new_hover_flag_; bool is_ground_; bool follow_traj_finished_; bool is_armed_; bool emergency_stop_flag_; // ROS NodeHandle ros::NodeHandle nh_; ros::NodeHandle pnh_; // ROS Subscribers ros::Subscriber odom_sub_; ros::Subscriber flight_status_sub_; ros::Subscriber mavros_state_sub_; ros::Subscriber plan_traj_sub_; ros::Subscriber goal_sub_; ros::Subscriber emergency_stop_sub_; // ROS Publishers ros::Publisher attitude_target_pub_; ros::Publisher follow_traj_finished_pub_; ros::Publisher ground_ctrl_fsm_pub_; ros::Publisher allow_plan_traj_pub_; // ROS Timers ros::Timer run_timer_; // ROS Topics std::string odometry_topic_; std::string attitude_target_topic_; std::string flight_status_topic_; std::string follow_traj_finished_topic_; std::string ground_ctrl_fsm_topic_; std::string mavros_state_topic_; std::string plan_traj_topic_; std::string goal_topic_; std::string allow_plan_traj_topic_; std::string emergency_stop_topic_; // Variables common::trajectory::CurEstimate<float> cur_estimate_; // Have been initialized to zero TrajAnal traj_; Trajectory<5, 2> minco_traj_; double traj_duration_; ros::Time start_time_; geometry_msgs::PoseStamped goal_; double goal_received_time_; bool allow_plan_traj_; int traj_id_; // PID Controller Parameters PIDParams position_pid_params_; PIDParams velocity_pid_params_; // Common Parameters CommonParams common_params_; // Thrust Parameters float thrust_return_; bool use_thrust_change_; // Visualizer the trajectory common::visual::TrajectoryVisualizer::Ptr traj_visualizer_; // Motion Controller MotionControllerSeparate::Ptr motion_controller_; // Functions void changeFSMExecState(FSM_EXEC_STATE new_state, string pos_call); void printFSMExecState(); // Callback functions void odomCallback(const nav_msgs::Odometry::ConstPtr &msg_ptr); void flightStatusCallback(const std_msgs::Bool::ConstPtr &msg_ptr); void mavrosStateCallback(const mavros_msgs::State::ConstPtr &msg_ptr); void planTrajCallback(const carstatemsgs::Polynome::ConstPtr &msg_ptr); void goalCallback(const geometry_msgs::PoseStamped::ConstPtr &msg_ptr); void emergencyStopCallback(const std_msgs::Bool::ConstPtr &msg_ptr); void runTimerCallback(const ros::TimerEvent &event); void publishAttitudeTarget(const std::pair<float, float> &desired_attitude, const float &feedforward_pitch_rate, const float &feedforward_yaw_rate); }; #endif // CTRL_FSM_PLANNING_H 注释上述代码
09-20
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值