Skip to content

Commit 193941a

Browse files
committed
course files uploaded
0 parents  commit 193941a

File tree

122 files changed

+7728
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+7728
-0
lines changed

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Compiled Object files
2+
*.slo
3+
*.lo
4+
*.o
5+
*.obj
6+
7+
# Precompiled Headers
8+
*.gch
9+
*.pch
10+
11+
# Compiled Dynamic libraries
12+
*.so
13+
*.dylib
14+
*.dll
15+
16+
# Fortran module files
17+
*.mod
18+
19+
# Compiled Static libraries
20+
*.lai
21+
*.la
22+
*.a
23+
*.lib
24+
25+
# Executables
26+
*.exe
27+
*.out
28+
*.app

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Modern_Robotics
2+
All code/projects created for EECS 397: Modern Robotics
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
cmake_minimum_required(VERSION 2.8.3)
2+
project(action_server_project)
3+
4+
find_package(catkin_simple REQUIRED)
5+
6+
catkin_simple()
7+
8+
# example boost usage
9+
# find_package(Boost REQUIRED COMPONENTS system thread)
10+
11+
# C++0x support - not quite the same as final C++11!
12+
# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
13+
14+
# Libraries
15+
# cs_add_library(my_lib src/my_lib.cpp)
16+
17+
# Executables
18+
cs_add_executable(amplitude_frequency_action_client src/amplitude_frequency_action_client.cpp)
19+
cs_add_executable(velocity_commander_action_server src/velocity_commander_action_server.cpp)
20+
cs_add_executable(controller src/controller.cpp)
21+
cs_add_executable(simulator src/simulator.cpp)
22+
23+
cs_install()
24+
cs_export()
25+

action_server_project/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Action Server Project
2+
3+
This package manipulates the velocity of an object by controlling the force placed on the object. A action client node (amplitude_frequency_action_client.cpp) get user input to determine an amplitude, a frequency, and a number of cycles (periods). The client then requests that the amplitude, frequency, and number of cycles in the action service node (velocity_commander_action_server.cpp) are changed to match. The action server uses the amplitude and frequency to calculate a sine wave and uses the number of cycles to determine how many periods to run for. The sine wave is then calculated with the given amplitude and frequency. The sine wave represents what the velocity should be. This is the velocity command (vel_cmd). This is handed off to the controller which calculates the force needed in order to increase/decrease the current velocity to match the vel_cmd. The simulator then changes the current velocity based on the calculated force.
4+
5+
## Example usage
6+
In command line:
7+
roscd
8+
roscore
9+
10+
In a second command line prompt:
11+
roslaunch action_server_project action_server_project.launch
12+
13+
In a third command line prompt:
14+
rqt_plot
15+
16+
In a fourth command line prompt:
17+
rosrun action_server_project amplitude_frequency_action_client
18+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#goal
2+
float64 requested_amplitude
3+
float64 requested_frequency
4+
int32 requested_num_cycles
5+
---
6+
#result
7+
bool goal_succeeded
8+
---
9+
#feedback
10+
int32 fdbk
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<launch>
2+
<!-- <node name= "amplitude_frequency_action_client" pkg= "action_server_project" type= "amplitude_frequency_action_client" /> -->
3+
<node name= "velocity_commander_action_server" pkg= "action_server_project" type= "velocity_commander_action_server" />
4+
<node name= "controller" pkg= "action_server_project" type= "controller" />
5+
<node name= "simulator" pkg= "action_server_project" type= "simulator" />
6+
</launch>

action_server_project/package.xml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0"?>
2+
<package>
3+
<name>action_server_project</name>
4+
<version>0.0.0</version>
5+
<description>The action_server_project package</description>
6+
7+
<!-- One maintainer tag required, multiple allowed, one person per tag -->
8+
<!-- Example: -->
9+
<!-- <maintainer email="[email protected]">Jane Doe</maintainer> -->
10+
<maintainer email="[email protected]">user</maintainer>
11+
12+
<!-- One license tag required, multiple allowed, one license per tag -->
13+
<!-- Commonly used license strings: -->
14+
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
15+
<license>TODO</license>
16+
17+
18+
<!-- Url tags are optional, but mutiple are allowed, one per tag -->
19+
<!-- Optional attribute type can be: website, bugtracker, or repository -->
20+
<!-- Example: -->
21+
<!-- <url type="website">http://ros.org/wiki/jacobian_publisher</url> -->
22+
23+
24+
<!-- Author tags are optional, mutiple are allowed, one per tag -->
25+
<!-- Authors do not have to be maintianers, but could be -->
26+
<!-- Example: -->
27+
<!-- <author email="[email protected]">Jane Doe</author> -->
28+
29+
30+
<!-- The *_depend tags are used to specify dependencies -->
31+
<!-- Dependencies can be catkin packages or system dependencies -->
32+
<!-- Examples: -->
33+
<!-- Use build_depend for packages you need at compile time: -->
34+
<build_depend>message_generation</build_depend>
35+
<!-- Use buildtool_depend for build tool packages: -->
36+
<!-- <buildtool_depend>catkin</buildtool_depend> -->
37+
<!-- Use run_depend for packages you need at runtime: -->
38+
<run_depend>message_runtime</run_depend>
39+
<!-- Use test_depend for packages you need only for testing: -->
40+
<!-- <test_depend>gtest</test_depend> -->
41+
<build_depend>actionlib</build_depend>
42+
<build_depend>simple_action_client</build_depend>
43+
<buildtool_depend>catkin</buildtool_depend>
44+
<buildtool_depend>catkin_simple</buildtool_depend>
45+
<build_depend>roscpp</build_depend>
46+
<build_depend>std_msgs</build_depend>
47+
<run_depend>roscpp</run_depend>
48+
<run_depend>std_msgs</run_depend>
49+
<run_depend>actionlib</run_depend>
50+
<run_depend>simple_action_client</run_depend>
51+
<!-- The export tag contains other, unspecified, tags -->
52+
<export>
53+
<!-- You can specify that this package is a metapackage here: -->
54+
<!-- <metapackage/> -->
55+
56+
<!-- Other tools can request additional information be placed here -->
57+
</export>
58+
</package>
59+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include <ros/ros.h>
2+
#include <std_msgs/Float64.h>
3+
#include <std_msgs/Int32.h>
4+
#include <actionlib/client/simple_action_client.h>
5+
#include <action_server_project/amplitude_frequency_msgAction.h>
6+
7+
// This function will be called once when the goal completes
8+
// this is optional, but it is a convenient way to get access to the "result" message sent by the server
9+
void doneCb(const actionlib::SimpleClientGoalState& state, const action_server_project::amplitude_frequency_msgResultConstPtr& result) {
10+
if(result->goal_succeeded){
11+
ROS_INFO("Goal has been succeeded! Yay!");
12+
} else {
13+
ROS_INFO("Goal did not succeed... boooo");
14+
}
15+
}
16+
17+
int main(int argc, char** argv) {
18+
ros::init(argc, argv, "amplitude_frequency_action_client_node"); //name of this node
19+
20+
action_server_project::amplitude_frequency_msgGoal goal;
21+
22+
actionlib::SimpleActionClient<action_server_project::amplitude_frequency_msgAction> action_client("amplitude_frequency_action", true);
23+
24+
// attempt to connect to the server:
25+
ROS_INFO("waiting for server: ");
26+
bool server_exists = action_client.waitForServer(ros::Duration(5.0)); // wait for up to 5 seconds
27+
//something odd in above: does not seem to wait for 5 seconds, but returns rapidly if server not running
28+
//bool server_exists = action_client.waitForServer(); //wait forever
29+
30+
if (!server_exists) {
31+
ROS_WARN("could not connect to server; halting");
32+
return 0; // bail out
33+
}
34+
35+
ROS_INFO("connected to action server"); // if here, then we connected to the server;
36+
37+
while(true) {
38+
std_msgs::Float64 amplitude;
39+
std_msgs::Float64 frequency;
40+
std_msgs::Int32 numCycles;
41+
std::cout << "Please enter in a desired amplitude: ";
42+
std::cin >> amplitude.data;
43+
44+
std::cout << "Please enter in a desired frequency: ";
45+
std::cin >> frequency.data;
46+
47+
std::cout << "Please enter in a desired number of cycles: ";
48+
std::cin >> numCycles.data;
49+
50+
//set the amplitude/frequency/number of cycles to be equal to user input and then send the goal
51+
goal.requested_amplitude = amplitude.data;
52+
goal.requested_frequency = frequency.data;
53+
goal.requested_num_cycles = numCycles.data;
54+
action_client.sendGoal(goal,&doneCb);
55+
56+
bool finished_before_timeout = action_client.waitForResult(ros::Duration(5.0));
57+
//bool finished_before_timeout = action_client.waitForResult(); // wait forever...
58+
if (!finished_before_timeout) {
59+
ROS_WARN("giving up waiting on result for goal");
60+
return 0;
61+
} else {
62+
//if here, then server returned a result to us
63+
}
64+
65+
}
66+
67+
return 0;
68+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// minimal_controller node:
2+
// wsn example node that both subscribes and publishes--counterpart to minimal_simulator
3+
// subscribes to "velocity" and publishes "force_cmd"
4+
// subscribes to "vel_cmd"
5+
#include <ros/ros.h>
6+
#include <std_msgs/Float64.h>
7+
//global variables for callback functions to populate for use in main program
8+
std_msgs::Float64 g_velocity;
9+
std_msgs::Float64 g_vel_cmd;
10+
std_msgs::Float64 g_force; // this one does not need to be global...
11+
12+
void myCallbackVelocity(const std_msgs::Float64& message_holder) {
13+
// check for data on topic "velocity"
14+
ROS_INFO("received velocity value is: %f", message_holder.data);
15+
g_velocity.data = message_holder.data; // post the received data in a global var for access by main prog.
16+
}
17+
18+
void myCallbackVelCmd(const std_msgs::Float64& message_holder) {
19+
// check for data on topic "vel_cmd"
20+
ROS_INFO("received velocity command value is: %f", message_holder.data);
21+
g_vel_cmd.data = message_holder.data; // post the received data in a global var for access by main prog.
22+
}
23+
24+
int main(int argc, char **argv) {
25+
ros::init(argc, argv, "velocity_controller"); //name this node
26+
// when this compiled code is run, ROS will recognize it as a node called "minimal_controller"
27+
ros::NodeHandle nh; // node handle
28+
//create 2 subscribers: one for state sensing (velocity) and one for velocity commands
29+
ros::Subscriber my_subscriber_object1 = nh.subscribe("velocity", 1, myCallbackVelocity);
30+
ros::Subscriber my_subscriber_object2 = nh.subscribe("vel_cmd", 1, myCallbackVelCmd);
31+
//publish a force command computed by this controller;
32+
ros::Publisher my_publisher_object = nh.advertise<std_msgs::Float64>("force_cmd", 1);
33+
double Kv = 1.0; // velocity feedback gain
34+
double dt_controller = 0.1; //specify 10Hz controller sample rate (pretty slow, but illustrative)
35+
double sample_rate = 1.0 / dt_controller; // compute the corresponding update frequency
36+
ros::Rate naptime(sample_rate); // use to regulate loop rate
37+
g_velocity.data = 0.0; //initialize velocity to zero
38+
g_force.data = 0.0; // initialize force to 0; will get updated by callback
39+
g_vel_cmd.data = 0.0; // init velocity command to zero
40+
double vel_err = 0.0; // velocity error
41+
// enter the main loop: get velocity state and velocity commands
42+
// compute command force to get system velocity to match velocity command
43+
// publish this force for use by the complementary simulator
44+
while (ros::ok()) {
45+
vel_err = g_vel_cmd.data - g_velocity.data; // compute error btwn desired and actual velocities
46+
g_force.data = Kv*vel_err; //proportional-only velocity-error feedback defines commanded force
47+
my_publisher_object.publish(g_force); // publish the control effort computed by this controller
48+
ROS_INFO("force command = %f", g_force.data);
49+
ros::spinOnce(); //allow data update from callback;
50+
naptime.sleep(); // wait for remainder of specified period;
51+
}
52+
return 0; // should never get here, unless roscore dies
53+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// minimal_simulator node:
2+
// wsn example node that both subscribes and publishes
3+
// does trivial system simulation, F=ma, to update velocity given F specified on topic "force_cmd"
4+
// publishes velocity on topic "velocity"
5+
#include <ros/ros.h>
6+
#include <std_msgs/Float64.h>
7+
std_msgs::Float64 g_velocity;
8+
std_msgs::Float64 g_force;
9+
10+
void myCallback(const std_msgs::Float64& message_holder) {
11+
// checks for messages on topic "force_cmd"
12+
ROS_INFO("received force value is: %f", message_holder.data);
13+
g_force.data = message_holder.data; // post the received data in a global var for access by main prog.
14+
}
15+
16+
int main(int argc, char **argv) {
17+
ros::init(argc, argv, "velocity_simulator"); //name this node
18+
// when this compiled code is run, ROS will recognize it as a node called "minimal_simulator"
19+
ros::NodeHandle nh; // node handle
20+
//create a Subscriber object and have it subscribe to the topic "force_cmd"
21+
ros::Subscriber my_subscriber_object = nh.subscribe("force_cmd", 1, myCallback);
22+
//simulate accelerations and publish the resulting velocity;
23+
ros::Publisher my_publisher_object = nh.advertise<std_msgs::Float64>("velocity", 1);
24+
double mass = 1.0;
25+
double dt = 0.01; //10ms integration time step
26+
double sample_rate = 1.0 / dt; // compute the corresponding update frequency
27+
ros::Rate naptime(sample_rate);
28+
g_velocity.data = 0.0; //initialize velocity to zero
29+
g_force.data = 0.0; // initialize force to 0; will get updated by callback
30+
while (ros::ok()) {
31+
g_velocity.data = g_velocity.data + (g_force.data / mass) * dt; // Euler integration of acceleration
32+
my_publisher_object.publish(g_velocity); // publish the system state (trivial--1-D)
33+
ROS_INFO("velocity = %f", g_velocity.data);
34+
ros::spinOnce(); //allow data update from callback
35+
naptime.sleep(); // wait for remainder of specified period; this loop rate is faster than
36+
// the update rate of the 10Hz controller that specifies force_cmd
37+
// however, simulator must advance each 10ms regardless
38+
}
39+
return 0; // should never get here, unless roscore dies
40+
}

0 commit comments

Comments
 (0)