Difference between revisions of "Lentin Joseph's chefbot Code"
From wikidb
(→Location) |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
= Location = | = Location = | ||
+ | |||
+ | * [https://github.com/qboticslabs/mastering_ros Mastering ROS git] | ||
~/ros_packages/LentinJoseph/mastering_ros/ | ~/ros_packages/LentinJoseph/mastering_ros/ | ||
Line 19: | Line 21: | ||
= Motor Control C++ Source = | = Motor Control C++ Source = | ||
− | cd ~/ros_packages/LentinJoseph/mastering_ros/chapter_9_codes/ | + | cd ~/ros_packages/LentinJoseph/mastering_ros/chapter_9_codes/chefbot_navig_cpp/src |
ls | ls | ||
bkup diff_tf.cpp twist_to_motor.cpp | bkup diff_tf.cpp twist_to_motor.cpp | ||
* twist_to_motor.cpp takes nav twist and converts to motor velocities | * twist_to_motor.cpp takes nav twist and converts to motor velocities | ||
+ | |||
+ | An interesting snippet. | ||
+ | |||
+ | * dx is target linear x speed in m/sec | ||
+ | * dy is target linear y speed in m/sec | ||
+ | * dr is target angular z speed in m/sec | ||
+ | * w wheelbase in m | ||
+ | |||
+ | <pre> | ||
+ | void TwistToMotors::init_variables() | ||
+ | { | ||
+ | left = 0; | ||
+ | right = 0; | ||
+ | |||
+ | dx = dy = dr =0; | ||
+ | |||
+ | w = 0.2 ; | ||
+ | rate = 50; | ||
+ | timeout_ticks = 2; | ||
+ | } | ||
+ | |||
+ | void TwistToMotors::spinOnce() | ||
+ | { | ||
+ | right = ( 1.0 * dx ) + (dr * w /2); | ||
+ | left = ( 1.0 * dx ) - (dr * w /2); | ||
+ | |||
+ | std_msgs::Float32 left_; | ||
+ | std_msgs::Float32 right_; | ||
+ | |||
+ | left_.data = left; | ||
+ | right_.data = right; | ||
+ | |||
+ | pub_lmotor.publish(left_); | ||
+ | pub_rmotor.publish(right_); | ||
+ | |||
+ | ticks_since_target += 1; | ||
+ | |||
+ | ros::spinOnce(); | ||
+ | } | ||
+ | |||
+ | void TwistToMotors::twistCallback(const geometry_msgs::Twist &msg) | ||
+ | { | ||
+ | ticks_since_target = 0; | ||
+ | |||
+ | dx = msg.linear.x; | ||
+ | dy = msg.linear.y; | ||
+ | dr = msg.angular.z; | ||
+ | } | ||
+ | |||
+ | </pre> |
Latest revision as of 23:19, 22 September 2017
Code
Location
~/ros_packages/LentinJoseph/mastering_ros/
Motor Control Python Scripts
cd ~/ros_packages/LentinJoseph/mastering_ros/chapter_9_codes/chefbot/chefbot_bringup/scripts ls bkup_working pid_velocity.py simple_navig_goals.py chefbot_teleop_key robot_gui.py twist_to_motors.py diff_tf.py SerialDataGateway.py launchpad_node.py SerialDataGateway.pyc
- pid_velocity.py takes wheel velocity commands and does pid power
- twist_to_motors.py takes navigation twist and converst to motor velocities
Motor Control C++ Source
cd ~/ros_packages/LentinJoseph/mastering_ros/chapter_9_codes/chefbot_navig_cpp/src ls bkup diff_tf.cpp twist_to_motor.cpp
- twist_to_motor.cpp takes nav twist and converts to motor velocities
An interesting snippet.
- dx is target linear x speed in m/sec
- dy is target linear y speed in m/sec
- dr is target angular z speed in m/sec
- w wheelbase in m
void TwistToMotors::init_variables() { left = 0; right = 0; dx = dy = dr =0; w = 0.2 ; rate = 50; timeout_ticks = 2; } void TwistToMotors::spinOnce() { right = ( 1.0 * dx ) + (dr * w /2); left = ( 1.0 * dx ) - (dr * w /2); std_msgs::Float32 left_; std_msgs::Float32 right_; left_.data = left; right_.data = right; pub_lmotor.publish(left_); pub_rmotor.publish(right_); ticks_since_target += 1; ros::spinOnce(); } void TwistToMotors::twistCallback(const geometry_msgs::Twist &msg) { ticks_since_target = 0; dx = msg.linear.x; dy = msg.linear.y; dr = msg.angular.z; }