-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from simchanu29/develop
Merge Develop into Master
- Loading branch information
Showing
32 changed files
with
951 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<mxfile userAgent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/7.9.5 Chrome/58.0.3029.110 Electron/1.7.5 Safari/537.36" version="8.7.7" editor="www.draw.io" type="device"><diagram id="82940445-f222-5b34-2bde-918a0ddb3653" name="Page-1">3V1bc9soFP41efUI0PVxe93ObHe6TWf20UNsYquVjEeS7aS/fnEsZAmIpcgY0Oah4xCo0TnfuR/QHXqfP30u8Hb9lS5Jdge95dMd+nAHYQgQ+/c48HwaQAk8DayKdHkaAueB+/Q3qQe9enSXLknZmVhRmlXptju4oJsNWVSdMVwU9NCd9kiz7rdu8YpIA/cLnMmj/6bLan0ajQPvPP4nSVdr/s3Aq//ygBe/VgXdbervu4Po8eXn9Occ8/+rnl+u8ZIeWkPo4x16X1BanT7lT+9JdiQtJ9tp3adX/trsuyCbasiCZh/VM392smSkqH+lRbWmK7rB2cfz6Lt1lWfsj4B9/Emq6rnmH95VlA2d1/xF6baedx6sB15oRI678Nhv8rbrJynprljUGwtrIOBiRfis5DR23HNrXf2snwnNSVU8swkFyXCV7rvsxTVKVs28M6XYh5pYrxAOTIdwXBpvS7mXpX8UBX5uTdjSdFOVrf/523GATeCaggtOrSh8L+jitW9+4glcO+3gzMPmUYaxFU6Irf5k2Bqit7E1AJrZGkyIrYnMVug7wdYYXpS+3vkwCPSyNZo4W0Mn2SpIX/98pFdaOan2ONvVj7zB+3TFSEA3MsezjLmFR84e1mlF7rf4heQH5ph2uf0qm/ak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v0vpDPphlNGi6NxInb5Oxs55TVnPQVtmV1YkDFJMl3zAFXYPUoDTzgim3ChnjcaUNVdO9uTSfDevCrwp2TdRy/pbPGIbwVkSxKj5Aeb0ubPRggJgCufM3huWJkS3wCG6yZeYvniNlyN+5RT7pkF88V0MZ3Hgg7D5MWco5CBLP9j6AT4MjopSjPYWh+EGdoyFNfOmtETRDeJKuVF8N21Uv8tcW3SpOKeRL+dNXUqv6F9fX4r4SS8zXuGYOzLMgBZ4ih5S4FkLLpr9tJC0Kx/mCyzfimH2TGzXdAy9+E9Ldcobc9DHFH4UXp7+14YMJ5Wc8EhzF871ICEujYHJXIcnB+38iuZtRi2304XiK5LgUNrokS7Zx+W0Kfbpb7u08cU0slnajKoG3KyLqE8XAcXrMQJ7umhUac8p4rny/iex4x/1FVOkIwLdaoritUNS6Vx3P56sZV7uY7BumKD46kN0w+NW7NeCMnvTIiN7pvVXuiTHGf8B</diagram></mxfile> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// | ||
// Created by simon on 25/06/18. | ||
// Licensed to Simon CHANU | ||
// | ||
|
||
#include <ros/ros.h> | ||
#include <geometry_msgs/Twist.h> | ||
#include <geometry_msgs/Pose.h> | ||
#include <tf/transform_datatypes.h> | ||
#include <std_msgs/Float64.h> | ||
|
||
class PIDHandler { | ||
/** | ||
* Gère les 2 PID pour la commande linéaire et la commande angulaire | ||
*/ | ||
public: | ||
PIDHandler(){ | ||
// Sub | ||
sub_cmd = node.subscribe("cmd_vel", 1, &PIDHandler::updateCmdVel, this); | ||
sub_pose = node.subscribe("pose_est", 1, &PIDHandler::updateHeading, this); | ||
sub_twist = node.subscribe("twist_est", 1, &PIDHandler::updateVel, this); | ||
sub_pid_vel = node.subscribe("pid_vel/control_effort", 1, &PIDHandler::updatePIDVel, this); | ||
sub_pid_head = node.subscribe("pid_head/control_effort", 1, &PIDHandler::updatePIDHead, this); | ||
|
||
// Pub | ||
pub_pidStateHead = node.advertise<std_msgs::Float64>("pid_head/state", 1); | ||
pub_pidCmdHead = node.advertise<std_msgs::Float64>("pid_head/setpoint", 1); | ||
pub_pidStateSpeed = node.advertise<std_msgs::Float64>("pid_vel/state", 1); | ||
pub_pidCmdSpeed = node.advertise<std_msgs::Float64>("pid_vel/setpoint", 1); | ||
pub_cmd_thrust = node.advertise<geometry_msgs::Twist>("cmd_thrust", 1); | ||
|
||
cmd_thrust.linear.x = 0.0; | ||
cmd_thrust.angular.z = 0.0; | ||
heading.data = 0.0; | ||
} | ||
|
||
void updateHeading(const geometry_msgs::Pose::ConstPtr& msg){ | ||
heading.data = tf::getYaw(msg->orientation); | ||
pub_pidStateHead.publish(heading); | ||
} | ||
|
||
void updateVel(const geometry_msgs::Twist::ConstPtr& msg){ | ||
std_msgs::Float64 vel; | ||
vel.data = msg->linear.x; | ||
pub_pidStateSpeed.publish(vel); | ||
} | ||
|
||
void updateCmdVel(const geometry_msgs::Twist::ConstPtr& msg){ | ||
std_msgs::Float64 cmdHead; | ||
std_msgs::Float64 cmdVel; | ||
cmdHead.data = msg->angular.z + heading.data; // On se replace dans un repere global | ||
cmdVel.data = msg->linear.x; | ||
pub_pidCmdHead.publish(cmdHead); | ||
pub_pidCmdSpeed.publish(cmdVel); | ||
} | ||
|
||
void updatePIDVel(const std_msgs::Float64::ConstPtr& msg){ | ||
cmd_thrust.linear.x = msg->data; | ||
} | ||
|
||
void updatePIDHead(const std_msgs::Float64::ConstPtr& msg){ | ||
cmd_thrust.angular.z = msg->data; | ||
} | ||
|
||
void spin(){ | ||
ros::Rate loop(10); | ||
while (ros::ok()){ | ||
// call all waiting callbacks | ||
ros::spinOnce(); | ||
|
||
// publish the command | ||
pub_cmd_thrust.publish(cmd_thrust); | ||
|
||
loop.sleep(); | ||
} | ||
} | ||
|
||
private: | ||
// Node | ||
ros::NodeHandle node; | ||
|
||
// Subscribers | ||
ros::Subscriber sub_cmd; | ||
ros::Subscriber sub_pose; | ||
ros::Subscriber sub_twist; | ||
ros::Subscriber sub_pid_vel; | ||
ros::Subscriber sub_pid_head; | ||
|
||
// Publishers | ||
ros::Publisher pub_pidStateSpeed; | ||
ros::Publisher pub_pidCmdSpeed; | ||
ros::Publisher pub_pidStateHead; | ||
ros::Publisher pub_pidCmdHead; | ||
ros::Publisher pub_cmd_thrust; | ||
|
||
// Internal variables | ||
std_msgs::Float64 heading; | ||
geometry_msgs::Twist cmd_thrust; | ||
}; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
// Node initialization | ||
std::cout << "Node initialization " << std::endl; | ||
ros::init(argc, argv, "PIDHandler"); | ||
|
||
PIDHandler pid; | ||
|
||
pid.spin(); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// | ||
// Created by simon on 19/06/18. | ||
// | ||
|
||
#include "algo.h" | ||
|
||
Algo::Algo() { | ||
debug = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Created by simon on 19/06/18. | ||
// | ||
|
||
#pragma once | ||
|
||
#include <map> | ||
#include <vector> | ||
|
||
class Algo { | ||
public: | ||
Algo(); | ||
|
||
virtual double run(std::vector<double> wp_a, std::vector<double> wp_b, std::vector<double> state_vec)= 0; | ||
|
||
bool debug; | ||
std::map<std::string, double> debugMap; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// | ||
// Created by simon on 19/06/18. | ||
// | ||
|
||
#include "lineFollow.h" | ||
|
||
LineFollow::LineFollow(){ | ||
|
||
}; | ||
|
||
double LineFollow::run(std::vector<double> wp_a, std::vector<double> wp_b, std::vector<double> state_vec){ | ||
|
||
double ax = wp_a[0]; | ||
printf("ax = [%f]\n",ax); | ||
double ay = wp_a[1]; | ||
printf("ay = [%f]\n",ay); | ||
double bx = wp_b[0]; | ||
printf("bx = [%f]\n",bx); | ||
double by = wp_b[1]; | ||
printf("by = [%f]\n",by); | ||
const double x = state_vec[0]; | ||
printf("x = [%f]\n",x); | ||
const double y = state_vec[1]; | ||
printf("y = [%f]\n",y); | ||
|
||
double headLine = atan2(by-ay,bx-ax); // ENU convention, angle from east | ||
printf("headLine = [%f]\n",headLine); | ||
|
||
// Si le bateau dépasse la ligne | ||
const double angleNextWp2Boat = atan2(y-by,x-bx); // ENU convention, angle from east | ||
printf("angleNextWp2Boat = [%f]\n",angleNextWp2Boat); | ||
printf("angle_rad(angleNextWp2Boat,-headLine) = [%f]\n",angle_rad(angleNextWp2Boat,-headLine)); | ||
if(fabs(angle_rad(angleNextWp2Boat,-headLine))<M_PI/2.0){ | ||
// If boat has crossed the line | ||
printf("===================== Inverting WayPoints\n"); | ||
|
||
const double tmpx = ax; | ||
const double tmpy = ay; | ||
ax = bx; | ||
ay = by; | ||
bx = tmpx; | ||
by = tmpy; | ||
|
||
headLine = atan2(by-ay,bx-ax); // ENU convention, angle from east | ||
} | ||
|
||
// Calcul de la distance à la ligne, si c'est un point alors une valeur est définie | ||
double dist2Line; | ||
if( sqrt( pow(bx-ax,2) + pow(by-ay,2)) != 0){ | ||
dist2Line = ((bx-ax)*(y-ay) - (by-ay)*(x-ax)) / sqrt( pow(bx-ax,2) + pow(by-ay,2)); | ||
} else{ dist2Line = 100; } | ||
printf("dist2Line = [%f]\n",dist2Line); | ||
|
||
// Calcul de l'erreur | ||
const double distAtanPt = 3; | ||
const double error = atan(dist2Line / distAtanPt); | ||
printf("headLine = [%f]\n", headLine); | ||
printf("error = [%f]\n", error); | ||
printf("headLine - error = [%f]\n", headLine - error); | ||
|
||
// Bornage entre -pi et pi | ||
const double wantedHead = angle_rad(headLine,- error); | ||
printf("wantedHead = [%f]\n", wantedHead); // Le cap voulu par rapport au repere global | ||
|
||
if(debug){ | ||
debugMap["wantedHead"] = wantedHead; | ||
debugMap["headLine"] = headLine; | ||
debugMap["angleNextWp2Boat"] = angleNextWp2Boat; | ||
debugMap["error"] = error; | ||
debugMap["dist2Line"] = dist2Line; | ||
debugMap["ax"] = ax; | ||
debugMap["ay"] = ay; | ||
debugMap["bx"] = bx; | ||
debugMap["by"] = by; | ||
} | ||
|
||
return wantedHead; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// Created by simon on 19/06/18. | ||
// | ||
|
||
#pragma once | ||
|
||
#include "vector" | ||
#include "algo.h" | ||
#include "geodesy/utility.h" | ||
|
||
class LineFollow: public Algo { | ||
public: | ||
LineFollow(); | ||
double run(std::vector<double> wp_a, std::vector<double> wp_b, std::vector<double> state_vec) override; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// Created by simon on 20/06/18. | ||
// | ||
|
||
#include <numeric> | ||
#include "pid.h" | ||
|
||
PID::PID(double p, double i, double d, int filterDepth, int intDepth) { | ||
this->p = p; | ||
this->i = i; | ||
this->d = d; | ||
this->filterDepth = filterDepth; | ||
this->intDepth = intDepth; | ||
integratedVal = 0; | ||
derivatedVal = 0; | ||
} | ||
|
||
PID::PID(double p, double i, double d): PID::PID(p, i, d, 3, 100){}; | ||
|
||
double PID::run(double target, double value) { | ||
// Handle memory | ||
if(mem.size()<filterDepth){ | ||
mem.insert(mem.begin(),target-value); | ||
} | ||
else{ | ||
const double smoothVal = std::accumulate(mem.begin(), mem.end(), 0.0)/mem.size(); | ||
mem.insert(mem.begin(), target-smoothVal); | ||
mem.erase(mem.end()); | ||
} | ||
const double smoothError = mem[0]; | ||
|
||
// compute derivatedVal | ||
if(mem.size()>=filterDepth){ | ||
const double derivatedValAfter = mem[0]; | ||
const double derivatedValBefore = mem[1]; | ||
derivatedVal = derivatedValAfter - derivatedValBefore; | ||
} | ||
|
||
// compute integratedVal | ||
integratedVal += mem[0]; | ||
|
||
// compute command | ||
const double u = p*smoothError + i*integratedVal + d*derivatedVal; | ||
|
||
return u; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// Created by simon on 20/06/18. | ||
// | ||
|
||
#pragma once | ||
|
||
#include <vector> | ||
|
||
class PID { | ||
public: | ||
PID(double p, double i, double d, int filterDepth, int intDepth); | ||
PID(double p, double i, double d): PID(p, i, d, 3, 100); | ||
double run(double target, double value); | ||
double p; | ||
double i; | ||
double d; | ||
double filterDepth; | ||
private: | ||
std::vector<double> mem; | ||
double integratedVal; | ||
double derivatedVal; | ||
}; |
Oops, something went wrong.